3 ## Copyright (C) 2004 NABEYA Kenichi (aka nanami@2ch)
4 ## Copyright (C) 2007-2012 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 set_player_values(player, hash)
66 each_group(true) do |group, players_hash|
67 players_hash.each do |key, value|
70 set_player_values(bp, value)
78 def set_player_values(player, hash)
79 return if player.nil? || hash.nil?
81 player.name = hash['name']
82 player.rate = hash['rate'] || 0
83 player.modified_at = hash['last_modified']
84 player.rating_group = hash['rating_group']
85 player.win = hash['win'] || 0
86 player.loss = hash['loss'] || 0
88 end # class Persistent
91 end # module ShogiServer