Class: Zold::Size

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/size.rb

Overview

Size

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ Size

Returns a new instance of Size.



32
33
34
# File 'lib/zold/size.rb', line 32

def initialize(bytes)
  @bytes = bytes
end

Instance Method Details

#to_sObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# 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