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.



7
8
9
# File 'lib/timetrap/models.rb', line 7

def round
  @round
end

Class Method Details

.sheetsObject



64
65
66
# File 'lib/timetrap/models.rb', line 64

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

Instance Method Details

#durationObject



34
35
36
# File 'lib/timetrap/models.rb', line 34

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

#duration=(nd) ⇒ Object



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

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

#endObject



26
27
28
# File 'lib/timetrap/models.rb', line 26

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

#end=(time) ⇒ Object



18
19
20
# File 'lib/timetrap/models.rb', line 18

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

#end_or_nowObject



41
42
43
# File 'lib/timetrap/models.rb', line 41

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

#round(time) ⇒ Object



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

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)


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

def round?
  !!self.class.round
end

#rounded_endObject



49
50
51
# File 'lib/timetrap/models.rb', line 49

def rounded_end
  round(self[:end])
end

#rounded_startObject



45
46
47
# File 'lib/timetrap/models.rb', line 45

def rounded_start
  round(self[:start])
end

#sheetObject



30
31
32
# File 'lib/timetrap/models.rb', line 30

def sheet
  self[:sheet].to_s
end

#startObject



22
23
24
# File 'lib/timetrap/models.rb', line 22

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

#start=(time) ⇒ Object



14
15
16
# File 'lib/timetrap/models.rb', line 14

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