Sha256: e8d1a18d2441a86c9b05a80922587b5b5b44544669e8c2e3f0aea3f92cafcce9

Contents?: true

Size: 456 Bytes

Versions: 1

Compression:

Stored size: 456 Bytes

Contents

module Humanize
  class Bytes
    VERSION = '2.2.0'

    def initialize(value)
      @value = value.to_f
    end

    def value
      @value
    end

    def to_s(options = {})
      size = options.fetch(:decimal_digits, nil)
      size ||= value.to_s.split('.').size == 1 ? 0 : value.to_s.split('.').last.size
      size = 0 if value.to_s.split('.').size >= 2 and value.to_s.split('.').last.to_s == '0'
      ("%.#{size}f" % value).to_s
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
humanize-bytes-2.2.0 lib/humanize/bytes.rb