Class: Lolita::Support::Bytes

Inherits:
Object
  • Object
show all
Defined in:
lib/support/bytes.rb

Overview

Convert bytes to closest possible unit.

Example

byte_converter=Lolita::FileUpload::Bytes.new(1024)
byte_converter.unit #=> kilobytes
byte_convertes.value #=> 1.0

Constant Summary collapse

@@default_unit =
"byte"
@@units =
%w(kilobyte megabyte gigabyte)

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ Bytes

Returns a new instance of Bytes.



13
14
15
16
# File 'lib/support/bytes.rb', line 13

def initialize(bytes)
  @power=0
  @bytes=bytes
end

Instance Method Details

#bytesObject

Return bytes



19
20
21
# File 'lib/support/bytes.rb', line 19

def bytes
  @bytes
end

#unitObject

Return unit name



24
25
26
# File 'lib/support/bytes.rb', line 24

def unit
  @unit||=set_unit
end

#valueObject

Return unit value



29
30
31
# File 'lib/support/bytes.rb', line 29

def value
  @value||=set_value
end