Sha256: 15fb007135a194e0f2f0a4280e2697f2714e0ac693a6ec6322d1468344613bde

Contents?: true

Size: 932 Bytes

Versions: 27

Compression:

Stored size: 932 Bytes

Contents

require 'delegate'

# Aruba
module Aruba
  # File Size
  class FileSize
    include Comparable

    private

    attr_reader :bytes, :divisor

    public

    # Create file size object
    def initialize(bytes)
      @bytes   = bytes
      @divisor = 1024
    end

    # Convert to bytes
    def to_byte
      bytes
    end
    alias to_i to_byte

    # Convert to float
    def to_f
      to_i.to_f
    end

    # Convert to string
    def to_s
      to_i.to_s
    end
    alias inspect to_s

    # Move to other
    def coerce(other)
      [bytes, other]
    end

    # Convert to kibi byte
    def to_kibi_byte
      to_byte.to_f / divisor
    end

    # Convert to mebi byte
    def to_mebi_byte
      to_kibi_byte.to_f / divisor
    end

    # Convert to gibi byte
    def to_gibi_byte
      to_mebi_byte.to_f / divisor
    end

    # Compare size with other size
    def <=>(other)
      to_i <=> other.to_i
    end
  end
end

Version data entries

27 entries across 27 versions & 3 rubygems

Version Path
aruba-1.0.4 lib/aruba/file_size.rb
aruba-1.0.3 lib/aruba/file_size.rb
aruba-1.0.2 lib/aruba/file_size.rb
aruba-1.0.1 lib/aruba/file_size.rb
aruba-1.0.0 lib/aruba/file_size.rb
aruba-0.14.14 lib/aruba/file_size.rb
aruba-0.14.13 lib/aruba/file_size.rb
aruba-1.0.0.pre.alpha.5 lib/aruba/file_size.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/aruba-0.14.12/lib/aruba/file_size.rb
aruba-0.14.12 lib/aruba/file_size.rb
aruba-0.14.11 lib/aruba/file_size.rb
aruba-0.14.10 lib/aruba/file_size.rb
aruba-1.0.0.pre.alpha.4 lib/aruba/file_size.rb
aruba-1.0.0.pre.alpha.3 lib/aruba/file_size.rb
aruba-0.14.9 lib/aruba/file_size.rb
aruba-0.14.8 lib/aruba/file_size.rb
aruba-0.14.7 lib/aruba/file_size.rb
aruba-0.14.6 lib/aruba/file_size.rb
aruba-0.14.5 lib/aruba/file_size.rb
aruba-0.14.4 lib/aruba/file_size.rb