Class: QTimetrap::Models::TimeEntry
- Inherits:
-
Object
- Object
- QTimetrap::Models::TimeEntry
- Defined in:
- app/models/time_entry.rb
Overview
Immutable time tracking entry model used across view and services.
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#sheet ⇒ Object
readonly
Returns the value of attribute sheet.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #day ⇒ Object
- #duration_seconds(now: Time.now) ⇒ Object
-
#initialize(id:, note:, sheet:, start_time:, end_time:) ⇒ TimeEntry
constructor
A new instance of TimeEntry.
- #project ⇒ Object
- #running? ⇒ Boolean
- #task ⇒ Object
Constructor Details
#initialize(id:, note:, sheet:, start_time:, end_time:) ⇒ TimeEntry
Returns a new instance of TimeEntry.
11 12 13 14 15 16 17 |
# File 'app/models/time_entry.rb', line 11 def initialize(id:, note:, sheet:, start_time:, end_time:) @id = id @note = note.to_s @sheet = sheet.to_s @start_time = start_time @end_time = end_time end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
9 10 11 |
# File 'app/models/time_entry.rb', line 9 def end_time @end_time end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'app/models/time_entry.rb', line 9 def id @id end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
9 10 11 |
# File 'app/models/time_entry.rb', line 9 def note @note end |
#sheet ⇒ Object (readonly)
Returns the value of attribute sheet.
9 10 11 |
# File 'app/models/time_entry.rb', line 9 def sheet @sheet end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
9 10 11 |
# File 'app/models/time_entry.rb', line 9 def start_time @start_time end |
Instance Method Details
#day ⇒ Object
38 39 40 |
# File 'app/models/time_entry.rb', line 38 def day (start_time || Time.now).to_date end |
#duration_seconds(now: Time.now) ⇒ Object
23 24 25 26 27 28 |
# File 'app/models/time_entry.rb', line 23 def duration_seconds(now: Time.now) return 0 unless start_time finish = end_time || now [finish.to_i - start_time.to_i, 0].max end |
#project ⇒ Object
30 31 32 |
# File 'app/models/time_entry.rb', line 30 def project split_sheet.first end |
#running? ⇒ Boolean
19 20 21 |
# File 'app/models/time_entry.rb', line 19 def running? end_time.nil? end |
#task ⇒ Object
34 35 36 |
# File 'app/models/time_entry.rb', line 34 def task split_sheet.last end |