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
- #duration ⇒ Object
- #duration=(nd) ⇒ Object
- #end ⇒ Object
- #end=(time) ⇒ Object
- #end_or_now ⇒ Object
- #round(time) ⇒ Object
- #round? ⇒ Boolean
- #rounded_end ⇒ Object
- #rounded_start ⇒ Object
- #sheet ⇒ 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
66 67 68 |
# File 'lib/timetrap/models.rb', line 66 def self.sheets map{|e|e.sheet}.uniq.sort end |
Instance Method Details
#duration ⇒ Object
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 |
#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]= Timer.process_time(time) end |
#end_or_now ⇒ Object
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
12 13 14 |
# File 'lib/timetrap/models.rb', line 12 def round? !!self.class.round end |
#rounded_end ⇒ Object
51 52 53 |
# File 'lib/timetrap/models.rb', line 51 def rounded_end round(self[:end]) end |
#rounded_start ⇒ Object
47 48 49 |
# File 'lib/timetrap/models.rb', line 47 def rounded_start round(self[:start]) end |
#sheet ⇒ Object
32 33 34 |
# File 'lib/timetrap/models.rb', line 32 def sheet self[:sheet].to_s 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]= Timer.process_time(time) end |