From e1cb51e727e7e4a4b49fa1f78a76e701b14da4f6 Mon Sep 17 00:00:00 2001 From: kakkoko Date: Tue, 24 Apr 2018 17:33:58 +0900 Subject: [PATCH] Add to support another format of memory size DMTF DSP0004(*1) defines flexible format of programatic units. (for instance, "byte * 2^10" == "kibibytes") This commit supports three often-used representation: * "byte * 2^10" (means "kibibytes") * "byte * 2^20" (means "mebibytes") * "byte * 2^30" (means "gibibytes") If you need complete support of DSP0004, you must implement more complex interpreter. (*1) http://www.dmtf.org/standards/published_documents/DSP0004_2.7.0.pdf --- lib/vagrant-mutate/box/virtualbox.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vagrant-mutate/box/virtualbox.rb b/lib/vagrant-mutate/box/virtualbox.rb index 34ec175..8216900 100644 --- a/lib/vagrant-mutate/box/virtualbox.rb +++ b/lib/vagrant-mutate/box/virtualbox.rb @@ -123,7 +123,7 @@ def ovf # defaults to false because ovf MB != megabytes def size_in_bytes(qty, unit, mib = false) qty = qty.to_i - unit = unit.downcase + unit = unit.downcase.gsub(/\s+/, '') unless mib case unit when 'kb', 'kilobytes' @@ -139,15 +139,15 @@ def size_in_bytes(qty, unit, mib = false) qty when 'kb', 'kilobytes' (qty * 1000) - when 'kib', 'kibibytes' + when 'kib', 'kibibytes', 'byte*2^10' (qty * 1024) when 'mb', 'megabytes' (qty * 1_000_000) - when 'm', 'mib', 'mebibytes' + when 'm', 'mib', 'mebibytes', 'byte*2^20' (qty * 1_048_576) when 'gb', 'gigabytes' (qty * 1_000_000_000) - when 'g', 'gib', 'gibibytes' + when 'g', 'gib', 'gibibytes', 'byte*2^30' (qty * 1_073_741_824) else fail ArgumentError, "Unknown unit #{unit}"