Class: Muon::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/muon/entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time, end_time, parent_hash = nil) ⇒ Entry

Returns a new instance of Entry.



7
8
9
10
# File 'lib/muon/entry.rb', line 7

def initialize(start_time, end_time, parent_hash = nil)
  @start_time, @end_time = start_time, end_time
  @parent_hash = parent_hash
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



5
6
7
# File 'lib/muon/entry.rb', line 5

def end_time
  @end_time
end

#parent_hashObject (readonly)

Returns the value of attribute parent_hash.



5
6
7
# File 'lib/muon/entry.rb', line 5

def parent_hash
  @parent_hash
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



5
6
7
# File 'lib/muon/entry.rb', line 5

def start_time
  @start_time
end

Class Method Details

.from_s(str) ⇒ Object



26
27
28
29
30
31
# File 'lib/muon/entry.rb', line 26

def self.from_s(str)
  parent_hash = str.lines.to_a[0].sub(/^parent /, "").strip
  parent_hash = nil if parent_hash == ""
  start_time, end_time = *str.lines.to_a[1].strip.split(",")
  new(Time.parse(start_time), Time.parse(end_time), parent_hash)
end

Instance Method Details

#durationObject



12
13
14
# File 'lib/muon/entry.rb', line 12

def duration
  (end_time - start_time).to_i
end

#to_sObject



21
22
23
24
# File 'lib/muon/entry.rb', line 21

def to_s
  "parent #{parent_hash}\n" +
  "#{start_time},#{end_time}\n"
end

#with_parent_hash(new_parent_hash) ⇒ Object



16
17
18
19
# File 'lib/muon/entry.rb', line 16

def with_parent_hash(new_parent_hash)
  raise "Already have parent hash" if parent_hash
  Entry.new(start_time, end_time, new_parent_hash)
end