Sha256: 70839b856c871d5c8e8e50e0ac10ed0dec2bc6e7e7a5cb412c095e83b744740d

Contents?: true

Size: 559 Bytes

Versions: 1

Compression:

Stored size: 559 Bytes

Contents

module Humanize
  module Bytes
    class Byte
      def initialize(value)
        @value = value
      end

      def value
        @value
      end

      def to_k
        @value / 1024.0
      end

      def to_m
        @value / 1024.0 / 1024
      end

      def to_g
        @value / 1024.0 / 1024 / 1024
      end

      def to_s
        @value.instance_of?(Float) ? formatted_float + ' bytes' : @value.to_s + ' bytes'
      end

      protected

      def formatted_float
        @value.to_s[0 .. @value.to_s.index('.') + 2]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
humanize-bytes-0.0.1 lib/humanize-bytes/byte.rb