Class: Numeric

Inherits:
Object
  • Object
show all
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

Instance Method Details

#agoObject

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

#dayObject 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_nowObject

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

#hourObject 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

#minuteObject 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

#monthObject

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

#secondObject 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

#weekObject 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