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



55
56
57
# File 'lib/timetrap/models.rb', line 55

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

Instance Method Details

#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]= Chronic.parse(time) || time
end

#end_or_nowObject



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

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

#round(time) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/timetrap/models.rb', line 44

def round time
  return nil unless time
  Time.at(
    if (r = time.to_i % 900) < 450
      time.to_i - r
    else
      time.to_i + (900 - 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



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

def rounded_end
  round(self[:end])
end

#rounded_startObject



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

def rounded_start
  round(self[:start])
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]= Chronic.parse(time) || time
end