Class: Numeric
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 ⇒ Object
TODO: Use 1024?.
- #to_ms ⇒ Object
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 ⇒ Object
TODO: Use 1024?
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/familia/core_ext.rb', line 125 def to_bytes args = case self.abs.to_i when (1000)..(1000**2) '%3.2f%s' % [(self / 1000.to_f).to_s, 'KB'] when (1000**2)..(1000**3) '%3.2f%s' % [(self / (1000**2).to_f).to_s, 'MB'] when (1000**3)..(1000**4) '%3.2f%s' % [(self / (1000**3).to_f).to_s, 'GB'] when (1000**4)..(1000**6) '%3.2f%s' % [(self / (1000**4).to_f).to_s, 'TB'] else [self.to_i, 'B'].join end end |
#to_ms ⇒ Object
120 121 122 |
# File 'lib/familia/core_ext.rb', line 120 def to_ms (self*1000.to_f) end |