edit created_at with a text field; add total weight calculation
| 15 | 27 | |
|---|---|---|
| 1 | 1 | class Exercise < ActiveRecord::Base |
| 2 | 2 | belongs_to :activity |
| 3 | ||
| 4 | def created_at_string | |
| 5 | created_at.to_s(:long) | |
| 6 | rescue ArgumentError | |
| 7 | Time.now.to_s(:long) | |
| 8 | end | |
| 9 | ||
| 10 | def created_at_string=(value) | |
| 11 | self.created_at = Time.parse(value) | |
| 12 | rescue ArgumentError | |
| 13 | @created_at_invalid = true | |
| 14 | end | |
| 15 | ||
| 16 | def validate | |
| 17 | errors.add(:created_at, 'is invalid') if @created_at_invalid | |
| 18 | end | |
| 19 | ||
| 20 | def total_weight | |
| 21 | if activity.use_reps? && activity.use_weight? | |
| 22 | reps * weight * ((activity.double_weight?) ? 2 : 1) | |
| 23 | else | |
| 24 | 0 | |
| 25 | end | |
| 26 | end | |
| 3 | 27 | end |
