class Zold::Size

Size

Public Class Methods

new(bytes) click to toggle source
# File lib/zold/size.rb, line 32
def initialize(bytes)
  @bytes = bytes
end

Public Instance Methods

to_s() click to toggle source
# File lib/zold/size.rb, line 36
def to_s
  if @bytes.nil?
    '?'
  elsif @bytes < 1024
    "#{@bytes}b"
  elsif @bytes < 1024 * 1024
    "#{(@bytes / 1024).round}Kb"
  elsif @bytes < 1024 * 1024 * 1024
    "#{(@bytes / (1024 * 1024)).round}Mb"
  else
    "#{(@bytes / (1024 * 1024 * 1024)).round}Gb"
  end
end