3 ## Copyright (C) 2004 NABEYA Kenichi (aka nanami@2ch)
4 ## Copyright (C) 2007-2008 Daigo Moriwaki (daigo at debian dot org)
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 # This manages those players who have their player_id.
26 # Since mk_rate mainly updates the yaml file, basically,
27 # this only reads data. But this writes some properties.
28 # TODO Such data should be facoted out to another file
31 def initialize(filename)
32 @db = YAML::Store.new(filename)
33 @db.transaction do |pstore|
34 @db['players'] ||= Hash.new
39 # trancaction=true means read only
41 def each_group(transaction=false)
42 @db.transaction(transaction) do
43 groups = @db["players"] || Hash.new
44 groups.each do |group, players|
50 def load_player(player)
51 return unless player.player_id
54 each_group(true) do |group, players|
55 hash = players[player.player_id]
61 player.name = hash['name']
62 player.rate = hash['rate'] || 0
63 player.modified_at = hash['last_modified']
64 player.rating_group = hash['rating_group']
65 player.win = hash['win'] || 0
66 player.loss = hash['loss'] || 0
71 each_group(true) do |group, players_hash|
72 players << players_hash.keys
74 return players.flatten.collect do |player_id|
76 p.player_id = player_id
81 end # class Persistent
84 end # module ShogiServer