Class: Activity
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Activity
- Defined in:
- app/models/activity.rb
Instance Attribute Summary collapse
-
#hours ⇒ Object
Returns the value of attribute hours.
-
#minutes ⇒ Object
Returns the value of attribute minutes.
Instance Method Summary collapse
- #calculate_hours ⇒ Object
-
#duration ⇒ Object
The duration of the task in minutes.
- #hours_minutes ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#hours ⇒ Object
Returns the value of attribute hours.
5 6 7 |
# File 'app/models/activity.rb', line 5 def hours @hours end |
#minutes ⇒ Object
Returns the value of attribute minutes.
5 6 7 |
# File 'app/models/activity.rb', line 5 def minutes @minutes end |
Instance Method Details
#calculate_hours ⇒ Object
21 22 23 24 25 26 |
# File 'app/models/activity.rb', line 21 def calculate_hours unless hours.empty? or minutes.empty? self.from = DateTime.now self.to = self.from + hours.to_i.hours + minutes.to_i.minutes end end |
#duration ⇒ Object
The duration of the task in minutes
29 30 31 32 33 |
# File 'app/models/activity.rb', line 29 def duration minutes = (to.to_f - from.to_f).to_i / 60 minutes < 0 ? 1.day.to_i + minutes : minutes end |
#hours_minutes ⇒ Object
17 18 19 |
# File 'app/models/activity.rb', line 17 def hours_minutes minutes || hours end |
#to_s ⇒ Object
35 36 37 |
# File 'app/models/activity.rb', line 35 def to_s "#{duration} => #{person}" end |