Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- documented/common/class_exts/numeric.rb
Overview
Represents a numeric value 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 ⇒ Integer
(also: #day)
Returns the numeric value converted to days.
-
#hours ⇒ Integer
(also: #hour)
Returns the numeric value converted to hours.
-
#minutes ⇒ Integer
(also: #minute)
Returns the numeric value converted to minutes.
-
#seconds ⇒ Integer
(also: #second)
Returns the numeric value as seconds.
-
#with_commas ⇒ String
Formats the numeric value with commas for thousands.
Instance Method Details
#ago ⇒ Time
Returns the time that was the given number of seconds ago from now.
32 33 34 |
# File 'documented/common/class_exts/numeric.rb', line 32 def ago Time.now - self end |
#as_time ⇒ String
Converts the numeric value to a time string in "HH:MM:SS" format.
16 17 18 |
# File 'documented/common/class_exts/numeric.rb', line 16 def as_time sprintf("%d:%02d:%02d", (self / 60).truncate, self.truncate % 60, ((self % 1) * 60).truncate) end |
#days ⇒ Integer Also known as: day
Returns the numeric value converted to days.
59 60 61 |
# File 'documented/common/class_exts/numeric.rb', line 59 def days return self * 86400 end |
#hours ⇒ Integer Also known as: hour
Returns the numeric value converted to hours.
52 53 54 |
# File 'documented/common/class_exts/numeric.rb', line 52 def hours return self * 3600 end |
#minutes ⇒ Integer Also known as: minute
Returns the numeric value converted to minutes.
45 46 47 |
# File 'documented/common/class_exts/numeric.rb', line 45 def minutes return self * 60 end |
#seconds ⇒ Integer Also known as: second
Returns the numeric value as seconds.
38 39 40 |
# File 'documented/common/class_exts/numeric.rb', line 38 def seconds return self end |
#with_commas ⇒ String
Formats the numeric value with commas for thousands.
24 25 26 |
# File 'documented/common/class_exts/numeric.rb', line 24 def with_commas self.to_s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse end |