struct

Measure::Weight

Inherits Comparable < Struct < Value < Object

Constructors

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

Instantiate a Weight instance with the given magnitude and Unit.

Source

Instance methods

*(scalar : Number) : self

Multiply by a scalar value

2.kg * 5
# => Measure::Length(@magnitude=10.0, @unit=Measure::Length::Unit::Kilogram)
Source
+(other : self) : self

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

1.kilogram + 1.pound
# => Measure::Weight(@magnitude=1.4535929094356397, @unit=Measure::Weight::Unit::Kilogram)
Source
-(other : self) : self

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

1.kilogram - 1.pound
# => Measure::Weight(@magnitude=0.5464070905643603, @unit=Measure::Weight::Unit::Kilogram)
Source
/(scalar : Number) : self

Multiply by a scalar value

10.kg / 2
# => Measure::Length(@magnitude=2.0, @unit=Measure::Length::Unit::Kilogram)
Source
<=>(other : self)

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

1.kg <=> 1.lb # => 1
1.lb <=> 1.lb # => 0
1.lb <=> 1.kg # => -1
1.lb < 1.kg   # => true
1.lb > 1.kg   # => false
Source
==(other : self)

Returns true if self and other are close enough to each other to be considered equivalent — within a femtogram (1/1_000_000_000_000_000th of a gram). 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.kilogram.

Source
to(unit : Unit) : self

Convert this instance to the given Unit.

1.kilogram.to(:lbs)
# => Measure::Weight(@magnitude=2.20462, @unit=Measure::Weight::Unit::Pound)
Source
to_s(io) : Nil

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

Source
total_grams

Returns the number of grams represented by this Weight instance

Source
unit

The unit used in measuring the weight.

Source

Nested types