struct Measure::Volume

Included Modules

Defined in:

volume.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(magnitude : Float64, unit : Measure::Volume::Unit) #

Instantiate a Volume instance with the given #magnitude and Unit.


[View source]

Instance Method Detail

def *(scalar : Number) : self #

Multiply by a scalar value

2.liters * 5
# => Measure::Volume(@magnitude=10.0, @unit=Measure::Volume::Unit::Liter)

[View source]
def +(other : self) : self #

Add two Volumes of any units together, returning an instance using self's Unit.

1.liter + 1.gallon
# => Measure::Volume(@magnitude=4.78541, @unit=Measure::Volume::Unit::Liter)

[View source]
def -(other : self) : self #

Subtract a Volume from self, returning an instance using self's Unit.

1.gallon - 1.liter
# => Measure::Volume(@magnitude=0.735764, @unit=Measure::Volume::Unit::Gallon)

[View source]
def /(scalar : Number) : self #

Divide by a scalar value

10.liters / 2
# => Measure::Volume(@magnitude=5.0, @unit=Measure::Volume::Unit::Liter)

[View source]
def <=>(other : self) #

Returns -1 if self is less than other, 0 if they're equal, or 1 otherwise.

1.gallon <=> 1.liter # => 1
1.liter <=> 1.liter  # => 0
1.liter <=> 1.gallon # => -1
1.liter < 1.gallon   # => true
1.liter > 1.gallon   # => false

[View source]
def ==(other : self) #

Returns true if self and other are close enough to each other to be considered equivalent. This isn't technically correct, but if you need that level of precision, open an issue and we can discuss how to support it.


[View source]
def magnitude : Float64 #

The numeric part of the measurement — the 1 in 1.liter.


[View source]
def to(unit : Unit) : self #

Convert this instance to the given Unit.

1.gallon.to(:liters)
# => Measure::Volume(@magnitude=3.78541, @unit=Measure::Volume::Unit::Liter)

[View source]
def to_s(io : IO) : Nil #

Output a human-readable representation of this Volume to the given IO.


[View source]
def total_liters : Float64 #

Returns the number of liters represented by this Volume instance


[View source]
def unit : Unit #

The unit used in measuring the volume.


[View source]