Class Filesize
In: lib/filesize.rb
Parent: Object

Methods

*   +   -   /   <=>   coerce   from   new   parse   pretty   to   to_f   to_i   to_int   to_s  

Included Modules

Comparable

Constants

TYPE_PREFIXES = { # Unit prefixes used for SI file sizes. :SI => %w{k M G T P E Z Y}, # Unit prefixes used for binary file sizes. :BINARY => %w{Ki Mi Gi Ti Pi Ei Zi Yi}
PREFIXES = TYPE_PREFIXES[:SI]   @deprecated Please use TYPE_PREFIXES[:SI] instead
SI = { :regexp => /^([\d,.]+)?[[:space:]]?([kmgtpezy]?)b?$/i, :multiplier => 1000, :prefixes => TYPE_PREFIXES[:SI], :presuffix => ''   Set of rules describing file sizes according to SI units.
BINARY = { :regexp => /^([\d,.]+)?[[:space:]]?(?:([kmgtpezy])i)?b?$/i, :multiplier => 1024, :prefixes => TYPE_PREFIXES[:BINARY], :presuffix => 'i'   Set of rules describing file sizes according to binary units.
PRECISION = 2   Set default precision
Floppy = Filesize.from("1474 KiB")   The size of a floppy disk
CD = Filesize.from("700 MB")   The size of a CD
DVD_5 = Filesize.from("4.38 GiB")   The size of a common DVD
DVD = DVD_5   The same as a DVD 5
DVD_9 = Filesize.from("7.92 GiB")   The size of a single-sided dual-layer DVD
DVD_10 = DVD_5 * 2   The size of a double-sided single-layer DVD
DVD_14 = DVD_9 + DVD_5   The size of a double-sided DVD, combining a DVD-9 and a DVD-5
DVD_18 = DVD_14 * 2   The size of a double-sided dual-layer DVD
ZIP = Filesize.from("100 MB")   The size of a Zip disk

Public Class methods

Parses a string, which describes a file size, and returns a Filesize object.

@param [String] arg A file size to parse. @raise [ArgumentError] Raised if the file size cannot be parsed properly. @return [Filesize]

@param [Number] size A file size, in bytes. @param [SI, BINARY] type Which type to use for conversions.

@return [Hash<:prefix, :size, :type>] @api private

Public Instance methods

@return [Array<self, other>] @api private

Same as {to_s} but with an automatic determination of the most sensible unit.

@return [String] @see to_s

@param [String] unit Which unit to convert to. @return [Float] Returns the size in a given unit.

to_f(unit = 'B')

Alias for to

@return [Number] Returns the size in bytes.

to_int()

Alias for to_i

@param (see to_f) @return [String] Same as {to_f}, but as a string, with the unit appended. @see to_f

[Validate]