class GasBlender::Measure
Constants
- PRECISION
Attributes
magnitude[R]
Public Class Methods
new(magnitude)
click to toggle source
# File lib/gas-blender/measure.rb, line 7 def initialize(magnitude) @magnitude = magnitude.to_f freeze end
Public Instance Methods
*(factor)
click to toggle source
# File lib/gas-blender/measure.rb, line 30 def *(factor) self.class.new(magnitude * factor.to_f) end
-(other)
click to toggle source
# File lib/gas-blender/measure.rb, line 25 def -(other) raise TypeError, "#{other.inspect} is not a #{self.class}" unless other.is_a?(self.class) self.class.new(magnitude - other.magnitude) end
/(denominator)
click to toggle source
# File lib/gas-blender/measure.rb, line 34 def /(denominator) if denominator.class == self.class magnitude / denominator.magnitude.to_f else self.class.new(magnitude / denominator.to_f) end end
<=>(other)
click to toggle source
# File lib/gas-blender/measure.rb, line 16 def <=>(other) other.is_a?(self.class) && magnitude <=> other.magnitude end
abs()
click to toggle source
# File lib/gas-blender/measure.rb, line 42 def abs self.class.new(magnitude.abs) end
hash()
click to toggle source
# File lib/gas-blender/measure.rb, line 21 def hash [magnitude, self.class].hash end
inspect()
click to toggle source
# File lib/gas-blender/measure.rb, line 12 def inspect "%.#{PRECISION}f" % magnitude end
zero?()
click to toggle source
# File lib/gas-blender/measure.rb, line 46 def zero? magnitude.round(PRECISION) == 0.0 end