Class: Logbook::Page
- Inherits:
-
Object
- Object
- Logbook::Page
- Defined in:
- lib/logbook/page.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#properties ⇒ Object
Returns the value of attribute properties.
Instance Method Summary collapse
- #add(entry) ⇒ Object
- #entry_at(line_number) ⇒ Object
-
#initialize ⇒ Page
constructor
A new instance of Page.
- #total_duration ⇒ Object
Constructor Details
#initialize ⇒ Page
Returns a new instance of Page.
5 6 7 |
# File 'lib/logbook/page.rb', line 5 def initialize @entries = [] end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
3 4 5 |
# File 'lib/logbook/page.rb', line 3 def entries @entries end |
#properties ⇒ Object
Returns the value of attribute properties.
3 4 5 |
# File 'lib/logbook/page.rb', line 3 def properties @properties end |
Instance Method Details
#add(entry) ⇒ Object
9 10 11 |
# File 'lib/logbook/page.rb', line 9 def add(entry) entries << entry end |
#entry_at(line_number) ⇒ Object
13 14 15 |
# File 'lib/logbook/page.rb', line 13 def entry_at(line_number) entries.reverse.find { |entry| entry.line_number <= line_number } end |
#total_duration ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/logbook/page.rb', line 17 def total_duration _, duration = entries.inject([nil, Duration.new(0)]) do |(previous_entry, duration), current_entry| if previous_entry && previous_entry.starts_clock? if current_entry.stops_clock? new_duration = Duration.new(duration.minutes + minutes_in_between(previous_entry, current_entry)) [current_entry, new_duration] else [previous_entry, duration] end else [current_entry, duration] end end duration end |