Sha256: 36bcdf1d035d3a56a9636cf11779845283a54ceafc533ab1147e74aeb80ffda4

Contents?: true

Size: 452 Bytes

Versions: 2

Compression:

Stored size: 452 Bytes

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

class Numeric
  FILESIZE_FORMAT = [
      ['%.1fT', 1 << 40],
      ['%.1fG', 1 << 30],
      ['%.1fM', 1 << 20],
      ['%.1fK', 1 << 10],
    ]

  def filesize_format
    FILESIZE_FORMAT.each do |format, size|
      return format % (self.to_f / size) if self >= size
    end

    self.to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ramaze-0.2.0 lib/ramaze/snippets/numeric/filesize_format.rb
ramaze-0.2.1 lib/ramaze/snippets/numeric/filesize_format.rb