Module: PackerFiles::Utils::Size
- Included in:
- Core::Disk, Core::LogicalVolume, Virtual::KVM, Virtual::VMWare, Virtual::VirtualBox
- Defined in:
- lib/PackerFiles/Utils/Size.rb
Overview
Contains utility functions to manage size conversions
Constant Summary collapse
- @@regex =
Array of regular expressions to match size and their corresponding lambda functions to return size in number. It is easy to understand the constants if we remember that Packer always accepts size in MiB [Power of 2].
{ /([0-9]+)GiB/ => lambda {|n| 1024 * n}, /([0-9]+)GB/ => lambda {|n| (953.67 * n).round}, /([0-9]+)MB/ => lambda {|n| (0.95367 * n).round}, /([0-9]+)MiB/ => lambda {|n| n}, /([0-9]+)TiB/ => lambda {|n| 1048576 * n}, /([0-9]+)TB/ => lambda {|n| (909486.46 * n).round}, /([0-9]+)GHz/ => lambda {|n| 1024 * n}, /([0-9]+)MHz/ => lambda {|n| n} }
Instance Method Summary collapse
-
#Bytes(size) ⇒ Object
Convert MiB Size into Bytes.
-
#MiB(size) ⇒ Object
Convert a text ‘size’ into a units of MiB.
Instance Method Details
#Bytes(size) ⇒ Object
Convert MiB Size into Bytes
36 37 38 |
# File 'lib/PackerFiles/Utils/Size.rb', line 36 def Bytes(size) size * 1024 * 1024 end |
#MiB(size) ⇒ Object
Convert a text ‘size’ into a units of MiB. This is done calling the appropriate lambda function, whenever the regex is matched.
27 28 29 30 31 32 33 |
# File 'lib/PackerFiles/Utils/Size.rb', line 27 def MiB(size) @@regex.each_pair do |r, l| if m = r.match(size) return l.call(m[1].to_i) end end end |