Class: Raykit::Log
- Inherits:
-
Hash
- Object
- Hash
- Raykit::Log
- Defined in:
- lib/raykit/log.rb
Instance Method Summary collapse
- #get_command_time(command) ⇒ Object
-
#initialize(filename) ⇒ Log
constructor
A new instance of Log.
- #save ⇒ Object
- #update_command_time(command, timestamp) ⇒ Object
Constructor Details
#initialize(filename) ⇒ Log
Returns a new instance of Log.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/raykit/log.rb', line 5 def initialize(filename) @filename=filename dir=File.dirname(@filename) FileUtils.mkdir_p(dir) if(!Dir.exist?(dir)) if(File.exist?(@filename)) begin data=JSON.parse(File.read(filename)) data.each{|k,v| self[k] = v } rescue end end end |
Instance Method Details
#get_command_time(command) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/raykit/log.rb', line 33 def get_command_time(command) if(self.has_key?("command_times")) command_times = self["command_times"] if(command_times.has_key?(command)) return DateTime.parse(command_times[command]) end end nil end |
#save ⇒ Object
20 21 22 |
# File 'lib/raykit/log.rb', line 20 def save File.open(@filename, 'w') {|f| f.write(JSON.generate(self)) } end |
#update_command_time(command, timestamp) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/raykit/log.rb', line 24 def update_command_time(command,) command_times = Hash.new() command_times = self["command_times"] if(self.has_key?("command_times")) command_times.delete(command) if(command_times.has_key?(command)) command_times[command] = .iso8601() self["command_times"] = command_times save end |