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.
7 8 9 |
# File 'lib/timetrap/models.rb', line 7 def round @round end |
Class Method Details
.sheets ⇒ Object
64 65 66 |
# File 'lib/timetrap/models.rb', line 64 def self.sheets map{|e|e.sheet}.uniq.sort end |
Instance Method Details
#duration ⇒ Object
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 |
#end ⇒ Object
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_now ⇒ Object
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
10 11 12 |
# File 'lib/timetrap/models.rb', line 10 def round? !!self.class.round end |
#rounded_end ⇒ Object
49 50 51 |
# File 'lib/timetrap/models.rb', line 49 def rounded_end round(self[:end]) end |
#rounded_start ⇒ Object
45 46 47 |
# File 'lib/timetrap/models.rb', line 45 def rounded_start round(self[:start]) end |
#sheet ⇒ Object
30 31 32 |
# File 'lib/timetrap/models.rb', line 30 def sheet self[:sheet].to_s end |
#start ⇒ Object
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 |