class ROdds::Odd::Decimal

Attributes

value[R]

Public Class Methods

new(value:) click to toggle source
# File lib/r_odds/odds/decimal.rb, line 5
def initialize(value:)
  if value.kind_of? Rational
    @value = value
  else
    raise ArgumentError, "Decimal odds must be initialized a Rational instance. Given a #{value.class} instance instead"
  end
end

Public Instance Methods

as_rational() click to toggle source
# File lib/r_odds/odds/decimal.rb, line 21
def as_rational
  value.rationalize
end
format() click to toggle source
# File lib/r_odds/odds/decimal.rb, line 13
def format
  :decimal
end
to_s(round_to: 2) click to toggle source
# File lib/r_odds/odds/decimal.rb, line 17
def to_s(round_to: 2)
  "%.#{round_to}f" % value
end