Module: EasyType::Mungers::Size

Defined in:
lib/easy_type/mungers.rb

Overview

The Size munger, munges a specified value to an Integer.

Instance Method Summary collapse

Instance Method Details

#unsafe_munge(size) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/easy_type/mungers.rb', line 28

def unsafe_munge(size)
  return size if size.is_a?(Numeric)
  case size
  when /^\d+(K|k)$/ then size.chop.to_i * 1024
  when /^\d+(M|m)$/ then size.chop.to_i * 1024 * 1024
  when /^\d+(G|g)$/ then size.chop.to_i * 1024 * 1024 * 1024
  when /^\d+$/ then size.to_i
  else
    fail('invalid size')
  end
end