Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- documented/common/class_exts/numeric.rb
Overview
Extends the Numeric class with additional time-related methods.
Instance Method Summary collapse
-
#ago ⇒ Time
Returns the time that was the given number of seconds ago from now.
-
#as_time ⇒ String
Converts the numeric value to a time string in “HH:MM:SS” format.
-
#days ⇒ Numeric
(also: #day)
Converts the numeric value to days in seconds.
-
#hours ⇒ Numeric
(also: #hour)
Converts the numeric value to hours in seconds.
-
#minutes ⇒ Numeric
(also: #minute)
Converts the numeric value to minutes in seconds.
-
#seconds ⇒ Numeric
(also: #second)
Returns the numeric value as seconds.
-
#with_commas ⇒ String
Formats the numeric value with commas as thousands separators.
Instance Method Details
#ago ⇒ Time
Returns the time that was the given number of seconds ago from now.
27 28 29 |
# File 'documented/common/class_exts/numeric.rb', line 27 def ago Time.now - self end |
#as_time ⇒ String
Converts the numeric value to a time string in “HH:MM:SS” format.
11 12 13 |
# File 'documented/common/class_exts/numeric.rb', line 11 def as_time sprintf("%d:%02d:%02d", (self / 60).truncate, self.truncate % 60, ((self % 1) * 60).truncate) end |
#days ⇒ Numeric Also known as: day
Converts the numeric value to days in seconds.
62 63 64 |
# File 'documented/common/class_exts/numeric.rb', line 62 def days return self * 86400 end |
#hours ⇒ Numeric Also known as: hour
Converts the numeric value to hours in seconds.
53 54 55 |
# File 'documented/common/class_exts/numeric.rb', line 53 def hours return self * 3600 end |
#minutes ⇒ Numeric Also known as: minute
Converts the numeric value to minutes in seconds.
44 45 46 |
# File 'documented/common/class_exts/numeric.rb', line 44 def minutes return self * 60 end |
#seconds ⇒ Numeric Also known as: second
Returns the numeric value as seconds.
35 36 37 |
# File 'documented/common/class_exts/numeric.rb', line 35 def seconds return self end |
#with_commas ⇒ String
Formats the numeric value with commas as thousands separators.
19 20 21 |
# File 'documented/common/class_exts/numeric.rb', line 19 def with_commas self.to_s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse end |