Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- documented/common/class_exts/numeric.rb
Overview
Extends the Numeric class to provide additional time and formatting methods. This class adds methods to convert numeric values into time formats and to format numbers with commas.
Instance Method Summary collapse
-
#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.
-
#hours ⇒ Numeric
(also: #hour)
Converts the numeric value to hours.
-
#minutes ⇒ Numeric
(also: #minute)
Converts the numeric value to minutes.
-
#seconds ⇒ Numeric
(also: #second)
Returns the numeric value as seconds.
-
#with_commas ⇒ String
Formats the numeric value as a string with commas separating thousands.
Instance Method Details
#as_time ⇒ String
Converts the numeric value to a time string in “HH:MM:SS” format.
14 15 16 |
# File 'documented/common/class_exts/numeric.rb', line 14 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.
57 58 59 |
# File 'documented/common/class_exts/numeric.rb', line 57 def days return self * 86400 end |
#hours ⇒ Numeric Also known as: hour
Converts the numeric value to hours.
48 49 50 |
# File 'documented/common/class_exts/numeric.rb', line 48 def hours return self * 3600 end |
#minutes ⇒ Numeric Also known as: minute
Converts the numeric value to minutes.
39 40 41 |
# File 'documented/common/class_exts/numeric.rb', line 39 def minutes return self * 60 end |
#seconds ⇒ Numeric Also known as: second
Returns the numeric value as seconds.
30 31 32 |
# File 'documented/common/class_exts/numeric.rb', line 30 def seconds return self end |
#with_commas ⇒ String
Formats the numeric value as a string with commas separating thousands.
22 23 24 |
# File 'documented/common/class_exts/numeric.rb', line 22 def with_commas self.to_s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse end |