Class: Lolita::Support::Bytes
- Inherits:
-
Object
- Object
- Lolita::Support::Bytes
- 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
-
#bytes ⇒ Object
Return bytes.
-
#initialize(bytes) ⇒ Bytes
constructor
A new instance of Bytes.
-
#unit ⇒ Object
Return unit name.
-
#value ⇒ Object
Return unit value.
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
#bytes ⇒ Object
Return bytes
19 20 21 |
# File 'lib/support/bytes.rb', line 19 def bytes @bytes end |
#unit ⇒ Object
Return unit name
24 25 26 |
# File 'lib/support/bytes.rb', line 24 def unit @unit||=set_unit end |
#value ⇒ Object
Return unit value
29 30 31 |
# File 'lib/support/bytes.rb', line 29 def value @value||=set_value end |