struct

Measure::Volume

Inherits Comparable < Struct < Value < Object

Constructors

new(magnitude : Float64, unit : Measure::Volume::Unit)

Instantiate a Volume instance with the given magnitude and Unit.

Source

Instance methods

*(scalar : Number) : self

Multiply by a scalar value

2.liters * 5
# => Measure::Volume(@magnitude=10.0, @unit=Measure::Volume::Unit::Liter)
Source
+(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)
Source
-(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)
Source
/(scalar : Number) : self

Divide by a scalar value

10.liters / 2
# => Measure::Volume(@magnitude=5.0, @unit=Measure::Volume::Unit::Liter)
Source
<=>(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
Source
==(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.

Source
magnitude

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

Source
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)
Source
to_s(io : IO) : Nil

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

Source
total_liters

Returns the number of liters represented by this Volume instance

Source
unit

The unit used in measuring the volume.

Source

Nested types