Class: KAG::User::User
- Inherits:
-
SymbolTable
- Object
- SymbolTable
- KAG::User::User
- Defined in:
- lib/kag/user/user.rb
Class Method Summary collapse
- .add_stat(user, stat, increment = 1) ⇒ Object
- .stats(user) ⇒ Object
- .subtract_stat(user, stat, decrement = 1) ⇒ Object
Instance Method Summary collapse
-
#initialize(user) ⇒ User
constructor
A new instance of User.
- #reload ⇒ Object
- #save ⇒ Object
-
#store(key, val) ⇒ Object
Sets the value of the given
key
toval
.
Constructor Details
#initialize(user) ⇒ User
Returns a new instance of User.
8 9 10 11 12 |
# File 'lib/kag/user/user.rb', line 8 def initialize(user) self[:authname] = user.authname super({}) self.merge!(_load) end |
Class Method Details
.add_stat(user, stat, increment = 1) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/kag/user/user.rb', line 31 def self.add_stat(user,stat,increment = 1) stat = stat.to_sym u = KAG::User::User.new(user) u[stat] = 0 unless u[stat] u[stat] = u[stat].to_i + increment.to_i u.save end |
.stats(user) ⇒ Object
50 51 52 53 |
# File 'lib/kag/user/user.rb', line 50 def self.stats(user) u = KAG::User::User.new(user) "#{user.nick} has played in #{u.matches.to_i} matches, has added #{u.adds.to_i} times, subbed #{u.substitutions.to_i} times, and has deserted matches #{u.desertions.to_i} times." end |
Instance Method Details
#reload ⇒ Object
14 15 16 17 |
# File 'lib/kag/user/user.rb', line 14 def reload puts "Reloading data file..." self.merge!(self._load) end |
#save ⇒ Object
25 26 27 28 29 |
# File 'lib/kag/user/user.rb', line 25 def save File.open("data/user/#{self.authname}.json","w") do |f| f.write(self.to_json) end end |
#store(key, val) ⇒ Object
Sets the value of the given key
to val
.
20 21 22 23 |
# File 'lib/kag/user/user.rb', line 20 def store(key, val) super(key,val) self.save end |