Class: QTimetrap::Models::TimeEntry

Inherits:
Object
  • Object
show all
Defined in:
app/models/time_entry.rb

Overview

Immutable time tracking entry model used across view and services.

Instance Attribute Summary collapse

Instance Method Summary collapse

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_timeObject (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

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'app/models/time_entry.rb', line 9

def id
  @id
end

#noteObject (readonly)

Returns the value of attribute note.



9
10
11
# File 'app/models/time_entry.rb', line 9

def note
  @note
end

#sheetObject (readonly)

Returns the value of attribute sheet.



9
10
11
# File 'app/models/time_entry.rb', line 9

def sheet
  @sheet
end

#start_timeObject (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

#dayObject



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

#projectObject



30
31
32
# File 'app/models/time_entry.rb', line 30

def project
  split_sheet.first
end

#running?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/models/time_entry.rb', line 19

def running?
  end_time.nil?
end

#taskObject



34
35
36
# File 'app/models/time_entry.rb', line 34

def task
  split_sheet.last
end