Class: Aruba::FileSize
- Inherits:
-
Object
- Object
- Aruba::FileSize
- Includes:
- Comparable
- Defined in:
- lib/aruba/file_size.rb
Overview
File Size
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare size with other size.
-
#coerce(other) ⇒ Object
Move to other.
-
#initialize(bytes) ⇒ FileSize
constructor
Create file size object.
-
#to_byte ⇒ Object
(also: #to_i)
Convert to bytes.
-
#to_f ⇒ Object
Convert to float.
-
#to_gibi_byte ⇒ Object
Convert to gibi byte.
-
#to_kibi_byte ⇒ Object
Convert to kibi byte.
-
#to_mebi_byte ⇒ Object
Convert to mebi byte.
-
#to_s ⇒ Object
(also: #inspect)
Convert to string.
Constructor Details
#initialize(bytes) ⇒ FileSize
Create file size object
16 17 18 19 |
# File 'lib/aruba/file_size.rb', line 16 def initialize(bytes) @bytes = bytes @divisor = 1024 end |
Instance Method Details
#<=>(other) ⇒ Object
Compare size with other size
59 60 61 |
# File 'lib/aruba/file_size.rb', line 59 def <=>(other) to_i <=> other.to_i end |
#coerce(other) ⇒ Object
Move to other
39 40 41 |
# File 'lib/aruba/file_size.rb', line 39 def coerce(other) [bytes, other] end |
#to_byte ⇒ Object Also known as: to_i
Convert to bytes
22 23 24 |
# File 'lib/aruba/file_size.rb', line 22 def to_byte bytes end |
#to_f ⇒ Object
Convert to float
28 29 30 |
# File 'lib/aruba/file_size.rb', line 28 def to_f to_i.to_f end |
#to_gibi_byte ⇒ Object
Convert to gibi byte
54 55 56 |
# File 'lib/aruba/file_size.rb', line 54 def to_gibi_byte to_mebi_byte.to_f / divisor end |
#to_kibi_byte ⇒ Object
Convert to kibi byte
44 45 46 |
# File 'lib/aruba/file_size.rb', line 44 def to_kibi_byte to_byte.to_f / divisor end |
#to_mebi_byte ⇒ Object
Convert to mebi byte
49 50 51 |
# File 'lib/aruba/file_size.rb', line 49 def to_mebi_byte to_kibi_byte.to_f / divisor end |
#to_s ⇒ Object Also known as: inspect
Convert to string
33 34 35 |
# File 'lib/aruba/file_size.rb', line 33 def to_s to_i.to_s end |