Class: SlimtimerTimeEntry

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/slimtimer_time_entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_labor(t_e) ⇒ Object



49
50
51
52
53
54
55
# File 'app/models/slimtimer_time_entry.rb', line 49

def self.create_labor(t_e)
  t_e.labor = Activity::Labor.create(
    :employee_id => (t_e.employee_slimtimer.nil?) ? nil : t_e.employee_slimtimer.employee_id,
    :comments    => t_e.comments,
    :minute_duration => ((t_e.end_time.to_f-t_e.start_time.to_f)/60).round
  ) if t_e.labor.nil?
end

Instance Method Details

#before_destroyObject



41
42
43
44
45
46
47
# File 'app/models/slimtimer_time_entry.rb', line 41

def before_destroy
  if labor and labor.activity and labor.activity.is_published  
    raise StandardError,"Can't commit time_entry delete to already published activity." 
  else
    labor.destroy if labor
  end
end

#friendly_durationObject



57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/slimtimer_time_entry.rb', line 57

def friendly_duration
  duration_min = (end_time - start_time)/60
  
  hour_part = (duration_min / 60).floor
  min_part  = (duration_min % 60).round
 
  (hour_part > 0) ? "%dhr %dmin" % [hour_part, min_part] : "#{min_part}min"
  
  rescue
    ""
end

#labelObject



8
9
10
11
12
13
14
15
16
17
# File 'app/models/slimtimer_time_entry.rb', line 8

def label
  trimmed_comments = comments.tr "\r\n", ''
  
  '%s (%s) %s "%s"' % [
    start_time.strftime('%m/%d/%y %I:%M%P'),
    friendly_duration,
    (slimtimer_task.nil?) ? '(Unknown)' : slimtimer_task.name,
    (trimmed_comments.length > 75) ? trimmed_comments[0...47]+'...' : trimmed_comments
  ]
end