Sha256: 1bcd4fef99129c3c300a1fdbb8cc8085f86e9432545741534b48fdbe6798418e

Contents?: true

Size: 455 Bytes

Versions: 1

Compression:

Stored size: 455 Bytes

Contents

module Humanize
  class Bytes
    VERSION = '2.1.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.1.0 lib/humanize/bytes.rb