Class: KAG::Help::Book

Inherits:
Hash
  • Object
show all
Includes:
Singleton
Defined in:
lib/kag/help/book.rb

Instance Method Summary collapse

Methods inherited from Hash

#random_key, #shuffle, #shuffle!

Constructor Details

#initialize(hash = nil) ⇒ Book

Returns a new instance of Book.



6
7
8
9
# File 'lib/kag/help/book.rb', line 6

def initialize(hash=nil)
  super
  self.merge!(self._load)
end

Instance Method Details

#_loadObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kag/help/book.rb', line 11

def _load
  unless File.exists?("config/help.json")
    return {}
  end
  f = ::IO.read("config/help.json")
  if f and !f.empty?
    SymbolTable.new(JSON.parse(f))
  else
    SymbolTable.new
  end
end

#reloadObject



23
24
25
26
# File 'lib/kag/help/book.rb', line 23

def reload
  puts "Reloading help file..."
  self.merge!(self._load)
end

#saveObject



34
35
36
37
38
# File 'lib/kag/help/book.rb', line 34

def save
  File.open("config/help.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/help/book.rb', line 29

def store(key, val)
  super(key,val)
  self.save
end