Class: BillTrap::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/billtrap/models.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.roundObject

Returns the value of attribute round.



165
166
167
# File 'lib/billtrap/models.rb', line 165

def round
  @round
end

Class Method Details

.sheetsObject



228
229
230
# File 'lib/billtrap/models.rb', line 228

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

Instance Method Details

#dateObject



172
173
174
# File 'lib/billtrap/models.rb', line 172

def date
 start.to_date
end

#durationObject



196
197
198
# File 'lib/billtrap/models.rb', line 196

def duration
  @duration ||= self.end_or_now.to_i - self.start.to_i
end

#endObject



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_nowObject



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

Returns:

  • (Boolean)


168
169
170
# File 'lib/billtrap/models.rb', line 168

def round?
  !!self.class.round
end

#rounded_endObject



213
214
215
# File 'lib/billtrap/models.rb', line 213

def rounded_end
  round(self[:end])
end

#rounded_startObject



209
210
211
# File 'lib/billtrap/models.rb', line 209

def rounded_start
  round(self[:start])
end

#sheetObject



192
193
194
# File 'lib/billtrap/models.rb', line 192

def sheet
  self[:sheet].to_s
end

#startObject



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