Module: Timespan::Units
- Included in:
- TimeDuration
- Defined in:
- lib/timespan/units.rb
Class Method Summary collapse
Instance Method Summary collapse
- #centuries=(number) ⇒ Object
- #decades=(number) ⇒ Object
- #seconds ⇒ Object (also: #to_secs, #to_seconds, #secs)
- #to_centuries ⇒ Object (also: #centuries)
- #to_days ⇒ Object (also: #to_d, #days)
- #to_decades ⇒ Object (also: #decades)
- #to_hours ⇒ Object (also: #to_h, #to_hrs, #hrs, #hours)
- #to_milliseconds ⇒ Object (also: #to_mils)
- #to_minutes ⇒ Object (also: #to_m, #to_mins, #mins, #minutes)
- #to_months ⇒ Object (also: #to_mon, #months)
- #to_weeks ⇒ Object (also: #to_w, #weeks)
- #to_years ⇒ Object (also: #to_y, #yrs, #to_yrs, #years)
- #units ⇒ Object
Class Method Details
.duration_units ⇒ Object
70 71 72 |
# File 'lib/timespan/units.rb', line 70 def self.duration_units %w{seconds minutes hours days weeks months years} end |
.units ⇒ Object
74 75 76 |
# File 'lib/timespan/units.rb', line 74 def self.units duration_units + %w{decades centuries} end |
Instance Method Details
#centuries=(number) ⇒ Object
93 94 95 |
# File 'lib/timespan/units.rb', line 93 def centuries= number self.decades = number * 10 end |
#decades=(number) ⇒ Object
89 90 91 |
# File 'lib/timespan/units.rb', line 89 def decades= number self.years = number * 10 end |
#seconds ⇒ Object Also known as: to_secs, to_seconds, secs
10 11 12 |
# File 'lib/timespan/units.rb', line 10 def seconds @seconds ||= duration.total end |
#to_centuries ⇒ Object Also known as: centuries
65 66 67 |
# File 'lib/timespan/units.rb', line 65 def to_centuries @to_centuries ||= (to_decades / 10.0).round end |
#to_days ⇒ Object Also known as: to_d, days
34 35 36 |
# File 'lib/timespan/units.rb', line 34 def to_days @to_days ||= (to_hours / 24.0).round end |
#to_decades ⇒ Object Also known as: decades
60 61 62 |
# File 'lib/timespan/units.rb', line 60 def to_decades @to_decades ||= (to_years / 10.0).round end |
#to_hours ⇒ Object Also known as: to_h, to_hrs, hrs, hours
26 27 28 |
# File 'lib/timespan/units.rb', line 26 def to_hours @to_hours ||= (to_minutes / 60.0).round end |
#to_milliseconds ⇒ Object Also known as: to_mils
3 4 5 |
# File 'lib/timespan/units.rb', line 3 def to_milliseconds @to_seconds ||= (seconds * 1000.0).round end |
#to_minutes ⇒ Object Also known as: to_m, to_mins, mins, minutes
18 19 20 |
# File 'lib/timespan/units.rb', line 18 def to_minutes @to_minutes ||= (to_seconds / 60.0).round end |
#to_months ⇒ Object Also known as: to_mon, months
46 47 48 |
# File 'lib/timespan/units.rb', line 46 def to_months @to_months ||= (to_days / 30.0).round end |
#to_weeks ⇒ Object Also known as: to_w, weeks
40 41 42 |
# File 'lib/timespan/units.rb', line 40 def to_weeks @to_weeks ||= (to_days / 7.0).round end |
#to_years ⇒ Object Also known as: to_y, yrs, to_yrs, years
52 53 54 |
# File 'lib/timespan/units.rb', line 52 def to_years @to_years ||= (to_days.to_f / 365.25).round end |