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
18 19 20 21 |
# File 'lib/aruba/file_size.rb', line 18 def initialize(bytes) @bytes = bytes @divisor = 1024 end |
Instance Method Details
#<=>(other) ⇒ Object
Compare size with other size
61 62 63 |
# File 'lib/aruba/file_size.rb', line 61 def <=>(other) to_i <=> other.to_i end |
#coerce(other) ⇒ Object
Move to other
41 42 43 |
# File 'lib/aruba/file_size.rb', line 41 def coerce(other) [bytes, other] end |
#to_byte ⇒ Object Also known as: to_i
Convert to bytes
24 25 26 |
# File 'lib/aruba/file_size.rb', line 24 def to_byte bytes end |
#to_f ⇒ Object
Convert to float
30 31 32 |
# File 'lib/aruba/file_size.rb', line 30 def to_f to_i.to_f end |
#to_gibi_byte ⇒ Object
Convert to gibi byte
56 57 58 |
# File 'lib/aruba/file_size.rb', line 56 def to_gibi_byte to_mebi_byte.to_f / divisor end |
#to_kibi_byte ⇒ Object
Convert to kibi byte
46 47 48 |
# File 'lib/aruba/file_size.rb', line 46 def to_kibi_byte to_byte.to_f / divisor end |
#to_mebi_byte ⇒ Object
Convert to mebi byte
51 52 53 |
# File 'lib/aruba/file_size.rb', line 51 def to_mebi_byte to_kibi_byte.to_f / divisor end |
#to_s ⇒ Object Also known as: inspect
Convert to string
35 36 37 |
# File 'lib/aruba/file_size.rb', line 35 def to_s to_i.to_s end |