Class: Zold::Size
- Inherits:
-
Object
- Object
- Zold::Size
- Defined in:
- lib/zold/size.rb
Overview
Size
Instance Method Summary collapse
-
#initialize(bytes) ⇒ Size
constructor
A new instance of Size.
- #to_s ⇒ Object
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_s ⇒ Object
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 |