module GxG::Units::Bytes

Public Class Methods

categories() click to toggle source
# File lib/gxg/gxg_units.rb, line 73
def self.categories()
  [:numeric, :byte, :memory, :storage, :computer]
end
interpret(quanta_string="",interpret_for_locale=:en_US,interpret_for_numeric_base=10) click to toggle source
# File lib/gxg/gxg_units.rb, line 76
def self.interpret(quanta_string="",interpret_for_locale=:en_US,interpret_for_numeric_base=10)
  multiplier = nil
  #
  case quanta_string.to_s.downcase.to_sym
    # Attribution: http://whatsabyte.com/
    # Attribution: https://en.wikipedia.org/wiki/Exabyte
    # Note: I am electing to count along the 1024 (to the power) rule.  Hard drive manufacturers can kiss my rosey-red,
    # I'll not bugger my enumeration standard for their bloody sales force. :P  Thus:
    # I've attempted to include the IS and IEC terms and abbreviations.
    # LATER: add ability to distinguish case: Kb = kiloBIT, KB = KiloBYTE, etc
  when :byte, :bytes
    multiplier = 1
  when :kb, :kib, :kilobyte, :kilobytes, :kibibyte, :kibibytes
    multiplier = 1024 ** 1
  when :mb, :mib, :megabyte, :megabytes, :mebibyte, :mebibytes
    multiplier = 1024 ** 2
  when :gb, :gib, :gigabyte, :gigabytes, :gibibyte, :gibibytes
    multiplier = 1024 ** 3
  when :tb, :tib, :terabyte, :terabytes, :tebibyte, :tebibytes
    multiplier = 1024 ** 4
  when :pb, :pib, :petabyte, :petabytes, :pebibyte, :pebibytes
    multiplier = 1024 ** 5
  when :eb, :eib, :exobyte, :exobytes, :exbibyte, :exbibytes
    multiplier = 1024 ** 6
  when :zb, :zib, :zettabyte, :zettabytes, :zebibyte, :zebibytes
    multiplier = 1024 ** 7
  when :yb, :yib, :yottabyte, :yottabytes, :yobibyte, :yobibytes
    multiplier = 1024 ** 8
  when :bb, :bib, :brontobyte, :brontobytes
    multiplier = 1024 ** 9
  when :geopbyte, :geopbytes
    # TODO: GeopByte: need to find missing SI and IEC abbreviations
    multiplier = 1024 ** 10
  end
  #
  if multiplier
    {:quantum => {:byte => multiplier}, :attributes => nil}
  else
    nil
  end
end