Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/common/class_exts/numeric.rb
Overview
Carve out from lich.rbw extension to Numeric class 2024-06-13
Instance Method Summary collapse
-
#as_time ⇒ String
Converts the numeric value to a time string in the format “H:MM:SS”.
-
#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 in seconds.
-
#with_commas ⇒ String
Formats the numeric value with commas as thousands separators.
Instance Method Details
#as_time ⇒ String
Converts the numeric value to a time string in the format “H:MM:SS”.
10 11 12 |
# File 'lib/common/class_exts/numeric.rb', line 10 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.
58 59 60 |
# File 'lib/common/class_exts/numeric.rb', line 58 def days return self * 86400 end |
#hours ⇒ Numeric Also known as: hour
Converts the numeric value to hours.
48 49 50 |
# File 'lib/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.
38 39 40 |
# File 'lib/common/class_exts/numeric.rb', line 38 def minutes return self * 60 end |
#seconds ⇒ Numeric Also known as: second
Returns the numeric value in seconds.
28 29 30 |
# File 'lib/common/class_exts/numeric.rb', line 28 def seconds return self end |
#with_commas ⇒ String
Formats the numeric value with commas as thousands separators.
19 20 21 |
# File 'lib/common/class_exts/numeric.rb', line 19 def with_commas self.to_s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse end |