Class: Activity::Labor
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Activity::Labor
- Includes:
- ActivityTypeModelHelper, ExtensibleObjectHelper
- Defined in:
- app/models/activity/labor.rb,
app/models/activity/labor/slimtimer.rb
Instance Method Summary collapse
- #as_legacy_ledger_row ⇒ Object
- #clock_duration ⇒ Object (also: #duration)
- #duration=(val) ⇒ Object
- #friendly_duration ⇒ Object
-
#initialize(*args) ⇒ Labor
constructor
A new instance of Labor.
- #name ⇒ Object
- #validate_duration ⇒ Object
Methods included from ActivityTypeModelHelper
Methods included from ExtensibleObjectHelper
Constructor Details
#initialize(*args) ⇒ Labor
Returns a new instance of Labor.
4 5 6 7 8 |
# File 'app/models/activity/labor.rb', line 4 def initialize(*args) # NOTE: This must be declared before the ActivityTypeModelHelper super(*args) self.minute_duration = 0 if minute_duration.nil? end |
Instance Method Details
#as_legacy_ledger_row ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/activity/labor.rb', line 62 def as_legacy_ledger_row begin hourly_rate = '%.2f' % employee.labor_rate_for(activity.client).hourly_rate.to_f rescue hourly_rate = ' ' end begin item_name = 'Labor-'+employee.short_name rescue item_name = 'Labor' end [ '%.2fhr' % (minute_duration.to_f/60), hourly_rate, '%.2f' % activity.cost.to_f, item_name, occurred_on.strftime('%m/%d/%y'), comments.try(:tr, "\r\n", '') ] end |
#clock_duration ⇒ Object Also known as: duration
56 57 58 |
# File 'app/models/activity/labor.rb', line 56 def clock_duration "%02d:%02d" % [ (minute_duration/60).floor, (minute_duration % 60).round ] unless minute_duration.nil? end |
#duration=(val) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/activity/labor.rb', line 27 def duration=(val) val = val.to_s unless val.class.name == 'String' self.minute_duration = @duration = case val # 40, 40m when /^[ ]*([\d]+)[ ]*[m]?[ ]*$/ then $1.to_i # 1h, 1hr when /^[ ]*([\d]+)[ ]*(h|hr)[ ]*$/ then $1.to_i*60 # 1h 40m, 1 40, 1:15 when /^[ ]*([\d]+)[ ]*(?:hr|[h\:]?)[ ]*([\d]{1,2})[ ]*[m]?[ ]*$/ then $1.to_i*60+$2.to_i # empty string? when /^[ ]*$/ then 0 else raise StandardError end rescue @duration = val end |
#friendly_duration ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/models/activity/labor.rb', line 47 def friendly_duration hour = (self.minute_duration / 60).floor min = (self.minute_duration % 60).round (hour > 0) ? sprintf( "%dhr %dmin", hour, min ) : "#{min}min" rescue "" end |
#name ⇒ Object
23 24 25 |
# File 'app/models/activity/labor.rb', line 23 def name type_quick_namer '%s at %s on %s', employee, client end |
#validate_duration ⇒ Object
19 20 21 |
# File 'app/models/activity/labor.rb', line 19 def validate_duration errors.add :duration, 'invalid' if !@duration.nil? and self.minute_duration != @duration end |