Class: ElapsedWatch::EventCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/elapsed_watch/event_collection.rb

Overview

The event collection holds all the events to watch.

Instance Method Summary collapse

Constructor Details

#initialize(event_file_name = nil) ⇒ EventCollection

Set up the EventCollection by passing in a file name that contains the events. If omitted or nil, the default file name at $HOME/.eventsrc will be used.



22
23
24
# File 'lib/elapsed_watch/event_collection.rb', line 22

def initialize(event_file_name=nil)
  self.event_file = event_file_name ||= DEFAULT_EVENT_FILE
end

Instance Method Details

#event_fileObject

Get the event file name



27
28
29
# File 'lib/elapsed_watch/event_collection.rb', line 27

def event_file()
  @event_file
end

#event_file=(fn) ⇒ Object

Assign the event file name and reload the contents of the file



32
33
34
35
# File 'lib/elapsed_watch/event_collection.rb', line 32

def event_file=(fn)
  @event_file=fn
  self.reload()
end

#reloadObject

Reload the events from the event file. Existing events are deleted first.



39
40
41
42
# File 'lib/elapsed_watch/event_collection.rb', line 39

def reload()
  self.clear
  self.concat File.read(event_file).split(/\r?\n/).map{|e| Event.new(e)}
end