Sha256: 79b20581c1f16f9073f72801b88071b40008c1d5fb11953500dfed8be6ed3874

Contents?: true

Size: 496 Bytes

Versions: 9

Compression:

Stored size: 496 Bytes

Contents


class Numeric
  include Time::Units
  # TODO: Use 1024?
  def to_bytes
    args = case self.abs.to_i
    when 0..1000
      [(self).to_s, 'B']
    when (1000)..(1000**2)
      [(self / 1000.to_f).to_s, 'KB']
    when (1000**2)..(1000**3)
      [(self / (1000**2).to_f).to_s, 'MB']
    when (1000**3)..(1000**4)
      [(self / (1000**3).to_f).to_s, 'GB']
    when (1000**4)..(1000**6)
      [(self / (1000**4).to_f).to_s, 'TB']
    else
      [self, 'B']
    end
    '%3.2f%s' % args
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
stella-0.7.3.002 lib/stella/mixins/numeric.rb
stella-0.7.3 lib/stella/mixins/numeric.rb
stella-0.7.2.003 lib/stella/mixins/numeric.rb
stella-0.7.2.002 lib/stella/mixins/numeric.rb
stella-0.7.2 lib/stella/mixins/numeric.rb
stella-0.7.1 lib/stella/mixins/numeric.rb
stella-0.7.0.019 lib/stella/mixins/numeric.rb
stella-0.7.0.018 lib/stella/mixins/numeric.rb
stella-0.7.0.017 lib/stella/mixins/numeric.rb