Module: Timespan::Units

Included in:
TimeDuration
Defined in:
lib/timespan/units.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.duration_unitsObject



70
71
72
# File 'lib/timespan/units.rb', line 70

def self.duration_units
	%w{seconds minutes hours days weeks months years}
end

.unitsObject



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

#secondsObject 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_centuriesObject 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_daysObject 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_decadesObject 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_hoursObject 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_millisecondsObject 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_minutesObject 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_monthsObject 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_weeksObject 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_yearsObject 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

#unitsObject



78
79
80
# File 'lib/timespan/units.rb', line 78

def units
	Timespan::Units.units
end