Class: KAG::Stats::Main
- Includes:
- Singleton
- Defined in:
- lib/kag/stats/main.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_load ⇒ Object
-
#initialize(hash = nil) ⇒ Main
constructor
A new instance of Main.
- #reload ⇒ Object
- #save ⇒ Object
-
#store(key, val) ⇒ Object
Sets the value of the given
key
toval
.
Methods inherited from Hash
#random_key, #shuffle, #shuffle!
Constructor Details
#initialize(hash = nil) ⇒ Main
Returns a new instance of Main.
6 7 8 9 |
# File 'lib/kag/stats/main.rb', line 6 def initialize(hash=nil) super self.merge!(self._load) end |
Class Method Details
Instance Method Details
#_load ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/kag/stats/main.rb', line 11 def _load unless File.exists?("data/index.json") return {} end f = ::IO.read("data/index.json") if f and !f.empty? SymbolTable.new(JSON.parse(f)) else SymbolTable.new end end |
#reload ⇒ Object
23 24 25 26 |
# File 'lib/kag/stats/main.rb', line 23 def reload puts "Reloading stats.main file..." self.merge!(self._load) end |
#save ⇒ Object
34 35 36 37 38 |
# File 'lib/kag/stats/main.rb', line 34 def save File.open("data/index.json","w") do |f| f.write(self.to_json) end end |
#store(key, val) ⇒ Object
Sets the value of the given key
to val
.
29 30 31 32 |
# File 'lib/kag/stats/main.rb', line 29 def store(key, val) super(key,val) self.save end |