class Leafy::Core::RatioGauge::Ratio

A ratio of one quantity to another.

Public Class Methods

new(numerator, denominator) click to toggle source
# File lib/leafy/core/ratio_gauge.rb, line 22
def initialize(numerator, denominator)
  @numerator = numerator
  @denominator = denominator
end
of(numerator, denominator) click to toggle source

Creates a new ratio with the given numerator and denominator.

@param numerator the numerator of the ratio @param denominator the denominator of the ratio @return {@code numerator:denominator}

# File lib/leafy/core/ratio_gauge.rb, line 18
def self.of(numerator, denominator)
  Ratio.new(numerator, denominator)
end

Public Instance Methods

to_s() click to toggle source
# File lib/leafy/core/ratio_gauge.rb, line 38
def to_s
  "#{@numerator.to_f}:#{@denominator.to_f}"
end
value() click to toggle source

Returns the ratio, which is either a {@code double} between 0 and 1 (inclusive) or {@code NaN}.

@return the ratio

# File lib/leafy/core/ratio_gauge.rb, line 31
def value
  if !(@denominator.is_a?(Float)) || @denominator.infinite? || @denominator.nan? || @denominator == 0
    return Float::NAN
  end
  @numerator.to_f / @denominator.to_f
end