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


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

Convert to float


28
29
30
# File 'lib/aruba/file_size.rb', line 28

def to_f
  to_i.to_f
end

#to_gibi_byteObject

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_byteObject

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_byteObject

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