Class: Timetrap::Entry

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/timetrap/models.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.roundObject

a class level instance variable that controls whether or not all entries should respond to #start and #end with times rounded to 15 minute increments.



9
10
11
# File 'lib/timetrap/models.rb', line 9

def round
  @round
end

Class Method Details

.sheetsObject



66
67
68
# File 'lib/timetrap/models.rb', line 66

def self.sheets
  map{|e|e.sheet}.uniq.sort
end

Instance Method Details

#durationObject



36
37
38
# File 'lib/timetrap/models.rb', line 36

def duration
  @duration ||= self.end_or_now.to_i - self.start.to_i
end

#duration=(nd) ⇒ Object



39
40
41
# File 'lib/timetrap/models.rb', line 39

def duration=( nd )
  @duration = nd.to_i
end

#endObject



28
29
30
# File 'lib/timetrap/models.rb', line 28

def end
  round? ? rounded_end : self[:end]
end

#end=(time) ⇒ Object



20
21
22
# File 'lib/timetrap/models.rb', line 20

def end= time
  self[:end]= Timer.process_time(time)
end

#end_or_nowObject



43
44
45
# File 'lib/timetrap/models.rb', line 43

def end_or_now
  self.end || (round? ? round(Time.now) : Time.now)
end

#round(time) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/timetrap/models.rb', line 55

def round time
  return nil unless time
  Time.at(
    if (r = time.to_i % Timetrap::Config['round_in_seconds']) < 450
      time.to_i - r
    else
      time.to_i + (Timetrap::Config['round_in_seconds'] - r)
    end
  )
end

#round?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/timetrap/models.rb', line 12

def round?
  !!self.class.round
end

#rounded_endObject



51
52
53
# File 'lib/timetrap/models.rb', line 51

def rounded_end
  round(self[:end])
end

#rounded_startObject



47
48
49
# File 'lib/timetrap/models.rb', line 47

def rounded_start
  round(self[:start])
end

#sheetObject



32
33
34
# File 'lib/timetrap/models.rb', line 32

def sheet
  self[:sheet].to_s
end

#startObject



24
25
26
# File 'lib/timetrap/models.rb', line 24

def start
  round? ? rounded_start : self[:start]
end

#start=(time) ⇒ Object



16
17
18
# File 'lib/timetrap/models.rb', line 16

def start= time
  self[:start]= Timer.process_time(time)
end