./lib/overload/integer.rb in lux-fw-0.5.37 vs ./lib/overload/integer.rb in lux-fw-0.6.2

- old
+ new

@@ -10,6 +10,21 @@ end def dotted self.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse end + + def to_filesize + base = 1024 + out = lambda do + { + 'B' => base, + 'KB' => base * base, + 'MB' => base * base * base, + 'GB' => base * base * base * base, + 'TB' => base * base * base * base * base + }.each_pair { |e, s| return "#{(self.to_f / (s / base)).round(1)} #{e}" if self < s } + end.call + + out.sub('.0 B', ' B') + end end