[PATCH/foreman 1/1] fixes #1166 - be more liberal in accepted values for to_gb - add better logging message

Signed-off-by: Tim Speetjens <tim.speetjens@gmail.com>

··· --- lib/core_extensions.rb | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/core_extensions.rb b/lib/core_extensions.rb
index 6b3d70f…5c3f3c9 100644
— a/lib/core_extensions.rb
+++ b/lib/core_extensions.rb
@@ -73,7 +73,7 @@ end
class String
def to_gb
begin

  •  value,unit=self.match(/(\d+|.+) ([KMG]B)$/i)[1..2]
    
  •  value,f,unit=self.match(/(\d+(\.\d+)?) ?(([KMG]B?|B))$/i)[1..3]
     case unit.to_sym
     when nil, :B, :byte          then (value.to_f / 1000_000_000)
     when :GB, :G, :gigabyte      then value.to_f
    

@@ -82,7 +82,7 @@ class String
else raise "Unknown unit: #{unit.inspect}!"
end
rescue

  •  raise "Unknown string"
    
  •  raise "Unknown string: #{self.inspect}!"
    
    end
    end
    end

    1.7.2.5

+1

··· On Thu, Oct 6, 2011 at 9:32 AM, Tim Speetjens wrote: > Signed-off-by: Tim Speetjens > --- > lib/core_extensions.rb | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/lib/core_extensions.rb b/lib/core_extensions.rb > index 6b3d70f..5c3f3c9 100644 > --- a/lib/core_extensions.rb > +++ b/lib/core_extensions.rb > @@ -73,7 +73,7 @@ end > class String > def to_gb > begin > - value,unit=self.match(/(\d+|.+) ([KMG]B)$/i)[1..2] > + value,f,unit=self.match(/(\d+(\.\d+)?) ?(([KMG]B?|B))$/i)[1..3] > case unit.to_sym > when nil, :B, :byte then (value.to_f / 1000_000_000) > when :GB, :G, :gigabyte then value.to_f > @@ -82,7 +82,7 @@ class String > else raise "Unknown unit: #{unit.inspect}!" > end > rescue > - raise "Unknown string" > + raise "Unknown string: #{self.inspect}!" > end > end > end > -- > 1.7.2.5 >