Class: Timelog::Entry
- Inherits:
-
Object
- Object
- Timelog::Entry
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/timelog/entry.rb
Instance Attribute Summary collapse
-
#archived ⇒ Object
(also: #archived?)
Returns the value of attribute archived.
-
#client ⇒ Object
Returns the value of attribute client.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#pauses ⇒ Object
readonly
Returns the value of attribute pauses.
-
#project ⇒ Object
Returns the value of attribute project.
-
#started ⇒ Object
Returns the value of attribute started.
-
#stopped ⇒ Object
Returns the value of attribute stopped.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #active_seconds ⇒ Object
- #active_time ⇒ Object
- #date ⇒ Object
-
#initialize ⇒ Entry
constructor
A new instance of Entry.
- #pause(at = Time.now) ⇒ Object
- #paused? ⇒ Boolean
- #paused_seconds ⇒ Object
- #paused_time ⇒ Object
- #resume(at = Time.now) ⇒ Object
- #started? ⇒ Boolean
- #status ⇒ Object
- #stopped? ⇒ Boolean
- #total_seconds ⇒ Object
- #total_time ⇒ Object
Constructor Details
#initialize ⇒ Entry
Returns a new instance of Entry.
10 11 12 13 |
# File 'lib/timelog/entry.rb', line 10 def initialize @pauses = {} @archived = false end |
Instance Attribute Details
#archived ⇒ Object Also known as: archived?
Returns the value of attribute archived.
6 7 8 |
# File 'lib/timelog/entry.rb', line 6 def archived @archived end |
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/timelog/entry.rb', line 5 def client @client end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/timelog/entry.rb', line 5 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/timelog/entry.rb', line 5 def id @id end |
#pauses ⇒ Object (readonly)
Returns the value of attribute pauses.
6 7 8 |
# File 'lib/timelog/entry.rb', line 6 def pauses @pauses end |
#project ⇒ Object
Returns the value of attribute project.
5 6 7 |
# File 'lib/timelog/entry.rb', line 5 def project @project end |
#started ⇒ Object
Returns the value of attribute started.
6 7 8 |
# File 'lib/timelog/entry.rb', line 6 def started @started end |
#stopped ⇒ Object
Returns the value of attribute stopped.
6 7 8 |
# File 'lib/timelog/entry.rb', line 6 def stopped @stopped end |
Instance Method Details
#active? ⇒ Boolean
87 88 89 |
# File 'lib/timelog/entry.rb', line 87 def active? !stopped? end |
#active_seconds ⇒ Object
50 51 52 |
# File 'lib/timelog/entry.rb', line 50 def active_seconds total_seconds - paused_seconds end |
#active_time ⇒ Object
65 66 67 |
# File 'lib/timelog/entry.rb', line 65 def active_time parse_seconds(active_seconds) end |
#date ⇒ Object
46 47 48 |
# File 'lib/timelog/entry.rb', line 46 def date started.try(:to_date) end |
#pause(at = Time.now) ⇒ Object
32 33 34 35 |
# File 'lib/timelog/entry.rb', line 32 def pause(at = Time.now) raise EntryAlreadyPaused if paused? @pauses[at] = nil end |
#paused? ⇒ Boolean
42 43 44 |
# File 'lib/timelog/entry.rb', line 42 def paused? @pauses.length > 0 and @pauses.values.last.nil? end |
#paused_seconds ⇒ Object
54 55 56 57 58 |
# File 'lib/timelog/entry.rb', line 54 def paused_seconds pauses.inject(0) do |seconds, pause| seconds + ((pause[1] || Time.now) - pause[0]) end.to_i end |
#paused_time ⇒ Object
69 70 71 |
# File 'lib/timelog/entry.rb', line 69 def paused_time parse_seconds(paused_seconds) end |
#resume(at = Time.now) ⇒ Object
37 38 39 40 |
# File 'lib/timelog/entry.rb', line 37 def resume(at = Time.now) raise EntryNotPaused unless paused? @pauses[@pauses.keys.last] = at end |
#started? ⇒ Boolean
24 25 26 |
# File 'lib/timelog/entry.rb', line 24 def started? @started end |
#status ⇒ Object
81 82 83 84 85 |
# File 'lib/timelog/entry.rb', line 81 def status return "archived" if archived? return "paused" if paused? return "active" if active? end |
#stopped? ⇒ Boolean
28 29 30 |
# File 'lib/timelog/entry.rb', line 28 def stopped? @stopped end |
#total_seconds ⇒ Object
60 61 62 63 |
# File 'lib/timelog/entry.rb', line 60 def total_seconds return 0 unless started? ((stopped || Time.now) - started).round end |
#total_time ⇒ Object
73 74 75 |
# File 'lib/timelog/entry.rb', line 73 def total_time parse_seconds(total_seconds) end |