Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Includes:
- Time::Units
- Defined in:
- lib/stella/core_ext.rb,
lib/stella/core_ext.rb
Overview
Statistics Module for Ruby © Derrick Pallas
Authors: Derrick Pallas Website: derrick.pallas.us/ruby-stats/ License: Academic Free License 3.0 Version: 2007-10-01b
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
- #fineround(len = 6.0) ⇒ Object
- #square ⇒ Object
-
#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
#fineround(len = 6.0) ⇒ Object
390 391 392 393 |
# File 'lib/stella/core_ext.rb', line 390 def fineround(len=6.0) v = (self * (10.0**len)).round / (10.0**len) v.zero? ? 0 : v end |
#square ⇒ Object
389 |
# File 'lib/stella/core_ext.rb', line 389 def square ; self * self ; end |
#to_bytes ⇒ Object
TODO: Use 1024?
258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/stella/core_ext.rb', line 258 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
253 254 255 |
# File 'lib/stella/core_ext.rb', line 253 def to_ms (self*1000.to_f) end |