Class: Aruba::FileSize

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/aruba/file_size.rb

Overview

File Size

Instance Method Summary collapse

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_byteObject 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_fObject

Convert to float



30
31
32
# File 'lib/aruba/file_size.rb', line 30

def to_f
  to_i.to_f
end

#to_gibi_byteObject

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_byteObject

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_byteObject

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_sObject 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