Class: Numeric
Overview
Extends the Numeric class with time unit and byte conversion functionality
Constant Summary
Constants included from Time::Units
Time::Units::PER_DAY, Time::Units::PER_HOUR, Time::Units::PER_MICROSECOND, Time::Units::PER_MILLISECOND, Time::Units::PER_MINUTE
Instance Method Summary collapse
-
#to_bytes ⇒ String
Converts the number to a human-readable byte representation using binary units.
-
#to_ms ⇒ Float
Converts the number to milliseconds.
Methods included from Time::Units
#days, #hours, #in_days, #in_hours, #in_microseconds, #in_milliseconds, #in_minutes, #in_seconds, #in_time, #in_weeks, #in_years, #microseconds, #milliseconds, #minutes, #seconds, #weeks, #years
Instance Method Details
#to_bytes ⇒ String
Converts the number to a human-readable byte representation using binary units
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/familia/core_ext.rb', line 123 def to_bytes units = %w[B KiB MiB GiB TiB] size = abs.to_f unit = 0 while size >= 1024 && unit < units.length - 1 size /= 1024 unit += 1 end format('%3.2f %s', size, units[unit]) end |
#to_ms ⇒ Float
Converts the number to milliseconds
110 111 112 |
# File 'lib/familia/core_ext.rb', line 110 def to_ms (self * 1000.to_f) end |