module UsefulUtilities::Size::Standard::Binary

Possible prefixes:

:B   - bytes
:KiB - kibibytes
:MiB - mebibytes
:GiB - gibibytes
:TiB - tebibytes

Used ISO standard en.wikipedia.org/wiki/Binary_prefix

Constants

GIBI
KIBI
MEBI
TEBI

Public Instance Methods

to_binary_bi(val, prefix) click to toggle source

@param val [Numeric] @param prefix [Symbol] @return [Numeric] val in bytes

# File lib/useful_utilities/size/standard/binary.rb, line 77
def to_binary_bi(val, prefix)
  case prefix
  when :B   then val
  when :KiB then val * KIBI
  when :MiB then val * MEBI
  when :GiB then val * GIBI
  when :TiB then val * TEBI
  else unsupported_unit!(prefix)
  end
end
to_gibi(val, prefix) click to toggle source

@param val [Numeric] @param prefix [Symbol] @return [Numeric] val in gibibytes

# File lib/useful_utilities/size/standard/binary.rb, line 35
def to_gibi(val, prefix)
  case prefix
  when :B   then val.fdiv(GIBI)
  when :KiB then val.fdiv(MEBI)
  when :MiB then val.fdiv(KIBI)
  when :GiB then val
  when :TiB then val * KIBI
  else unsupported_unit!(prefix)
  end
end
to_kibi(val, prefix) click to toggle source

@param val [Numeric] @param prefix [Symbol] @return [Numeric] val in kibibytes

# File lib/useful_utilities/size/standard/binary.rb, line 63
def to_kibi(val, prefix)
  case prefix
  when :B   then val.fdiv(KIBI)
  when :KiB then val
  when :MiB then val * KIBI
  when :GiB then val * MEBI
  when :TiB then val * GIBI
  else unsupported_unit!(prefix)
  end
end
to_mebi(val, prefix) click to toggle source

@param val [Numeric] @param prefix [Symbol] @return [Numeric] val in mebibytes

# File lib/useful_utilities/size/standard/binary.rb, line 49
def to_mebi(val, prefix)
  case prefix
  when :B   then val.fdiv(MEBI)
  when :KiB then val.fdiv(KIBI)
  when :MiB then val
  when :GiB then val * KIBI
  when :TiB then val * MEBI
  else unsupported_unit!(prefix)
  end
end
to_tebi(val, prefix) click to toggle source

@param val [Numeric] @param prefix [Symbol] @return [Numeric] val in tebibytes

# File lib/useful_utilities/size/standard/binary.rb, line 21
def to_tebi(val, prefix)
  case prefix
  when :B   then val.fdiv(TEBI)
  when :KiB then val.fdiv(GIBI)
  when :MiB then val.fdiv(MEBI)
  when :GiB then val.fdiv(KIBI)
  when :TiB then val
  else unsupported_unit!(prefix)
  end
end