Class: Timetrap::Entry
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Timetrap::Entry
- Defined in:
- lib/timetrap/models.rb
Class Attribute Summary collapse
-
.round ⇒ Object
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.
Class Method Summary collapse
Instance Method Summary collapse
- #end ⇒ Object
- #end=(time) ⇒ Object
- #end_or_now ⇒ Object
- #round(time) ⇒ Object
- #round? ⇒ Boolean
- #rounded_end ⇒ Object
- #rounded_start ⇒ Object
- #start ⇒ Object
- #start=(time) ⇒ Object
Class Attribute Details
.round ⇒ Object
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
.sheets ⇒ Object
55 56 57 |
# File 'lib/timetrap/models.rb', line 55 def self.sheets map{|e|e.sheet}.uniq.sort end |
Instance Method Details
#end ⇒ Object
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]= process_time(time) end |
#end_or_now ⇒ Object
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 % Timetrap::Config['round_in_seconds']) < 450 time.to_i - r else time.to_i + (Timetrap::Config['round_in_seconds'] - r) end ) end |
#round? ⇒ Boolean
12 13 14 |
# File 'lib/timetrap/models.rb', line 12 def round? !!self.class.round end |
#rounded_end ⇒ Object
40 41 42 |
# File 'lib/timetrap/models.rb', line 40 def rounded_end round(self[:end]) end |
#rounded_start ⇒ Object
36 37 38 |
# File 'lib/timetrap/models.rb', line 36 def rounded_start round(self[:start]) end |
#start ⇒ Object
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]= process_time(time) end |