Sha256: 3d54e9807cb9ccc55a000453d2137e7540ca935d6f82c106cf8ced5d2d7b9ac3

Contents?: true

Size: 922 Bytes

Versions: 14

Compression:

Stored size: 922 Bytes

Contents

class ByteNumber < Numeric
    def initialize(int)
        @int = int
    end

    def to_s
        @int.to_s
    end

    def to_i
        @int
    end

    def to_f
        @int.to_f
    end

    def to_B
        to_i
    end

    def to_KB
        _compute_unit_to_n_kilo(1)
    end

    def to_MB
        _compute_unit_to_n_kilo(2)
    end

    def to_GB
        _compute_unit_to_n_kilo(3)
    end

    def coerce(other)
        to_i.coerce(other)
    end

    def <=>(other)
        to_i <=> other
    end

    def +(other)
        to_i + other
    end

    def -(other)
        to_i - other
    end

    def *(other)
        to_i * other
    end

    def /(other)
        to_i / other
    end

    def pow(n)
        self.class.new(to_i ** n)
    end

    def self.from_GB(value)
        self.new(value*(1024**3))
    end

    private
    def _compute_unit_to_n_kilo(n=0)
        (to_f/(1024 ** n)).ceil
    end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
vagrant-libvirt-0.12.2 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.12.1 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.12.0 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.11.2 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.11.1 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.10.8 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.10.7 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.10.6 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.10.5 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.10.4 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.10.3 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.10.2 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.10.1 lib/vagrant-libvirt/util/byte_number.rb
vagrant-libvirt-0.10.0 lib/vagrant-libvirt/util/byte_number.rb