Sha256: 56f831b8073bdf7a074e1ac1b31d9257d735cdacce45097105a6698384f1c36b

Contents?: true

Size: 336 Bytes

Versions: 7

Compression:

Stored size: 336 Bytes

Contents

module Imgurr
  class Numbers
    class << self
      def to_human(number)
        units = %W(B KiB MiB GiB TiB)

        size, unit = units.reduce(number.to_f) do |(fsize, _), utype|
          fsize > 512 ? [fsize / 1024, utype] : (break [fsize, utype])
        end
        return "#{"%.3f" % size} #{unit}"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
imgurr-1.0.0 lib/imgurr/numbers.rb
imgurr-0.2.0 lib/imgurr/numbers.rb
imgurr-0.1.2 lib/imgurr/numbers.rb
imgurr-0.1.1 lib/imgurr/numbers.rb
imgurr-0.1.0 lib/imgurr/numbers.rb
imgurr-0.0.4 lib/imgurr/numbers.rb
imgurr-0.0.3 lib/imgurr/numbers.rb