Class: Todd::Task

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

Instance Method Summary collapse

Instance Method Details

#archive!Object



206
207
208
209
210
211
212
213
# File 'lib/todd/model.rb', line 206

def archive!
  return nil if running

  self[:archived] = true
  self.save

  self
end

#bundleObject



167
168
169
170
171
172
173
174
175
176
# File 'lib/todd/model.rb', line 167

def bundle
  {
    :type => :task,
    :id => id,
    :title => title,
    :active => running,
    :session_time => session_time,
    :total_time => total_time
  }
end

#restore!Object



215
216
217
218
219
220
# File 'lib/todd/model.rb', line 215

def restore!
  self[:archived] = false
  self.save
  
  self
end

#session_timeObject



222
223
224
# File 'lib/todd/model.rb', line 222

def session_time
  running ? Punch.find(current_punch).session_time : 0
end

#start!Object



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/todd/model.rb', line 178

def start!
  return nil if running

  punch = Punch.new
  punch.clock_in!

  self[:current_punch] = punch.id
  toggle(:running)

  self.save

  self
end

#stop!Object



192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/todd/model.rb', line 192

def stop!
  return nil if !running

  punch = Punch.find(current_punch)
  session_time = punch.clock_out!

  self[:total_time] += session_time if session_time
  toggle(:running)

  self.save

  self
end