lib/onering/util.rb in onering-client-0.0.75 vs lib/onering/util.rb in onering-client-0.0.76

- old
+ new

@@ -3,9 +3,33 @@ module String def nil_empty return nil if (self.strip.chomp.empty? rescue true) self.strip.chomp end + + def to_bytes + case self + when /^\s*([\d\.]+)\s*([KMGTPEZY]?)([Bb])\s*$/ + power = case $2 + when 'K' then 1 + when 'M' then 2 + when 'G' then 3 + when 'T' then 4 + when 'P' then 5 + when 'E' then 6 + when 'Z' then 7 + when 'Y' then 8 + else 0 + end + + num = (Integer($1) rescue Float($1)) + div = ($3 == 'b' ? 8 : 1) + + return ((num * (1024 ** power)) / div) + else + return nil + end + end end extend self \ No newline at end of file