Module: MoreCoreExtensions::IEC60027_2

Defined in:
lib/more_core_extensions/core_ext/string/iec60027_2.rb

Constant Summary collapse

IEC_60027_2_SIZE_SUFFIXES =

Support converting strings with an IEC60027-2 suffix to an integer physics.nist.gov/cuu/Units/binary.html Example: “1 Ki”.iec_60027_2_to_i => 1024

%w(Ki Mi Gi Ti Pi Ei Zi Yi).freeze

Instance Method Summary collapse

Instance Method Details

#iec_60027_2_to_iObject



8
9
10
11
12
13
14
15
# File 'lib/more_core_extensions/core_ext/string/iec60027_2.rb', line 8

def iec_60027_2_to_i
  suffix_index = IEC_60027_2_SIZE_SUFFIXES.index(self[-2..-1])
  if suffix_index.nil?
    Integer(self)
  else
    Integer(self[0..-3]) * (2**10)**(suffix_index + 1)
  end
end