Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/seconds.rb
Overview
Adds active_support/core_ext/numeric like methods to the Numeric class
e.g. 15.minutes returns 15 * 60 e.g. 15.minutes.ago returns a Time object whose value is 15 minutes less than Time.now
Instance Method Summary collapse
-
#ago ⇒ Object
Returns a Time object
selfseconds before Time.now. -
#day ⇒ Object
(also: #days)
Returns the number of seconds in
selfdays. -
#from(time) ⇒ Object
Returns a Time object
selfseconds after the given time. -
#from_now ⇒ Object
Returns a Time object
selfseconds from now. -
#hour ⇒ Object
(also: #hours)
Returns the number of seconds in
selfhours. -
#minute ⇒ Object
(also: #minutes)
Returns the number of seconds in
selfminutes. -
#month ⇒ Object
Returns the number of seconds in
selfmonths. -
#second ⇒ Object
(also: #seconds)
Returns the number of seconds in
selfseconds. -
#until(time) ⇒ Object
Returns a Time object
selfseconds before the given time. -
#week ⇒ Object
(also: #weeks)
Returns the number of seconds in
selfweeks.
Instance Method Details
#ago ⇒ Object
Returns a Time object self seconds before Time.now.
1.day.ago
90 91 92 |
# File 'lib/seconds.rb', line 90 def ago Time.now - self end |
#day ⇒ Object Also known as: days
Returns the number of seconds in self days. Intended to be used with the ago method.
1.day
=> 86400
54 55 56 |
# File 'lib/seconds.rb', line 54 def day 24*hour end |
#from(time) ⇒ Object
Returns a Time object self seconds after the given time.
1.hour.from(some_time)
114 115 116 |
# File 'lib/seconds.rb', line 114 def from time time + self end |
#from_now ⇒ Object
Returns a Time object self seconds from now.
in_an_hour = 1.hour.from_now
125 126 127 |
# File 'lib/seconds.rb', line 125 def from_now self.from Time.now end |
#hour ⇒ Object Also known as: hours
Returns the number of seconds in self hours. Intended to be used with the ago method.
1.hour
=> 3600
42 43 44 |
# File 'lib/seconds.rb', line 42 def hour 60*minute end |
#minute ⇒ Object Also known as: minutes
Returns the number of seconds in self minutes. Intended to be used with the ago method.
1.minute
=> 60
30 31 32 |
# File 'lib/seconds.rb', line 30 def minute 60*second end |
#month ⇒ Object
Returns the number of seconds in self months. Assumes a month is 28 days. Intended to be used with the ago method.
1.month
=> 2419200
78 79 80 |
# File 'lib/seconds.rb', line 78 def month 4*week end |
#second ⇒ Object Also known as: seconds
Returns the number of seconds in self seconds. Intended to be used with the ago method.
1.second
=> 1
17 18 19 |
# File 'lib/seconds.rb', line 17 def second self end |
#until(time) ⇒ Object
Returns a Time object self seconds before the given time.
1.hour.until(some_time)
101 102 103 |
# File 'lib/seconds.rb', line 101 def until time time - self end |
#week ⇒ Object Also known as: weeks
Returns the number of seconds in self weeks. Intended to be used with the ago method.
1.week
=> 604800
66 67 68 |
# File 'lib/seconds.rb', line 66 def week 7*day end |