Class: Logbook::Page
- Inherits:
-
Object
- Object
- Logbook::Page
- Defined in:
- lib/logbook/page.rb
Instance Attribute Summary collapse
-
#clock ⇒ Object
Returns the value of attribute clock.
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#logged_work ⇒ Object
Returns the value of attribute logged_work.
-
#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.
- #logged_time ⇒ Object
- #tasks ⇒ Object
Constructor Details
Instance Attribute Details
#clock ⇒ Object
Returns the value of attribute clock.
3 4 5 |
# File 'lib/logbook/page.rb', line 3 def clock @clock end |
#entries ⇒ Object
Returns the value of attribute entries.
3 4 5 |
# File 'lib/logbook/page.rb', line 3 def entries @entries end |
#logged_work ⇒ Object
Returns the value of attribute logged_work.
3 4 5 |
# File 'lib/logbook/page.rb', line 3 def logged_work @logged_work 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
11 12 13 14 |
# File 'lib/logbook/page.rb', line 11 def add(entry) entries << entry clock.tick(entry) { |tracked_entry, duration| logged_work.store(tracked_entry, duration) } end |
#entry_at(line_number) ⇒ Object
16 17 18 |
# File 'lib/logbook/page.rb', line 16 def entry_at(line_number) entries.reverse.find { |entry| entry.line_number <= line_number } end |
#logged_time ⇒ Object
20 21 22 |
# File 'lib/logbook/page.rb', line 20 def logged_time logged_work.map { |entry, duration| duration }.reduce(Duration.new(0), &:+) end |
#tasks ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/logbook/page.rb', line 24 def tasks entries.reduce({}) do |tasks, entry| case entry when TaskEntry, TaskDefinition if entry.belongs_to_task? task = tasks[entry.task_id] ||= Task.new(entry.task_id) if logged_work.has_key?(entry) task.log_work(entry, logged_work[entry]) else task.add_entry(entry) end end else end tasks end end |