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.



15
16
17
# File 'lib/zold/size.rb', line 15

def initialize(bytes)
  @bytes = bytes
end

Instance Method Details

#to_sObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/zold/size.rb', line 19

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