Class: Todd::Punch

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/todd/model.rb

Instance Method Summary collapse

Instance Method Details

#clock_in!Object



230
231
232
233
234
235
236
237
238
# File 'lib/todd/model.rb', line 230

def clock_in!
  return false if running
  self[:start] = Time.now
  toggle(:running)

  self.save
  
  true
end

#clock_out!Object



240
241
242
243
244
245
246
247
248
# File 'lib/todd/model.rb', line 240

def clock_out!
  return nil unless running
  self[:stop] = Time.now
  toggle(:running)

  self.save

  session_time
end

#session_timeObject



250
251
252
# File 'lib/todd/model.rb', line 250

def session_time
  running ? (Time.now - start) : (stop - start)
end