Class: BillTrap::Entry
- Inherits:
-
Object
- Object
- BillTrap::Entry
- Defined in:
- lib/billtrap/models.rb
Class Attribute Summary collapse
-
.round ⇒ Object
Returns the value of attribute round.
Class Method Summary collapse
Instance Method Summary collapse
- #date ⇒ Object
- #duration ⇒ Object
- #end ⇒ Object
- #end=(time) ⇒ Object
- #end_or_now ⇒ Object
- #round(time, roundsecs = ) ⇒ Object
- #round? ⇒ Boolean
- #rounded_end ⇒ Object
- #rounded_start ⇒ Object
- #sheet ⇒ Object
- #start ⇒ Object
- #start=(time) ⇒ Object
Class Attribute Details
.round ⇒ Object
Returns the value of attribute round.
165 166 167 |
# File 'lib/billtrap/models.rb', line 165 def round @round end |
Class Method Details
.sheets ⇒ Object
228 229 230 |
# File 'lib/billtrap/models.rb', line 228 def self.sheets map{|e|e.sheet}.uniq.sort end |
Instance Method Details
#date ⇒ Object
172 173 174 |
# File 'lib/billtrap/models.rb', line 172 def date start.to_date end |
#duration ⇒ Object
196 197 198 |
# File 'lib/billtrap/models.rb', line 196 def duration @duration ||= self.end_or_now.to_i - self.start.to_i end |
#end ⇒ Object
188 189 190 |
# File 'lib/billtrap/models.rb', line 188 def end round? ? rounded_end : self[:end] end |
#end=(time) ⇒ Object
180 181 182 |
# File 'lib/billtrap/models.rb', line 180 def end= time self[:end]= Timer.process_time(time) end |
#end_or_now ⇒ Object
205 206 207 |
# File 'lib/billtrap/models.rb', line 205 def end_or_now self.end || (round? ? round(Time.now) : Time.now) end |
#round(time, roundsecs = ) ⇒ Object
217 218 219 220 221 222 223 224 225 226 |
# File 'lib/billtrap/models.rb', line 217 def round time, roundsecs=BillTrap::Config['round_in_seconds'] return nil unless time Time.at( if (r = time.to_i % roundsecs) < 450 time.to_i - r else time.to_i + (roundsecs - r) end ) end |
#round? ⇒ Boolean
168 169 170 |
# File 'lib/billtrap/models.rb', line 168 def round? !!self.class.round end |
#rounded_end ⇒ Object
213 214 215 |
# File 'lib/billtrap/models.rb', line 213 def rounded_end round(self[:end]) end |
#rounded_start ⇒ Object
209 210 211 |
# File 'lib/billtrap/models.rb', line 209 def rounded_start round(self[:start]) end |
#sheet ⇒ Object
192 193 194 |
# File 'lib/billtrap/models.rb', line 192 def sheet self[:sheet].to_s end |
#start ⇒ Object
184 185 186 |
# File 'lib/billtrap/models.rb', line 184 def start round? ? rounded_start : self[:start] end |
#start=(time) ⇒ Object
176 177 178 |
# File 'lib/billtrap/models.rb', line 176 def start= time self[:start]= Timer.process_time(time) end |