Class: ROdds::Odd::Decimal
Instance Method Summary collapse
- #as_rational ⇒ Object
- #format ⇒ Object
-
#initialize(value:) ⇒ Decimal
constructor
A new instance of Decimal.
- #to_s(round_to: 2) ⇒ Object
Constructor Details
#initialize(value:) ⇒ Decimal
Returns a new instance of Decimal.
5 6 7 8 9 10 11 |
# 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 |
Instance Method Details
#as_rational ⇒ Object
21 22 23 |
# File 'lib/r_odds/odds/decimal.rb', line 21 def as_rational value.rationalize end |
#format ⇒ Object
13 14 15 |
# File 'lib/r_odds/odds/decimal.rb', line 13 def format :decimal end |
#to_s(round_to: 2) ⇒ Object
17 18 19 |
# File 'lib/r_odds/odds/decimal.rb', line 17 def to_s(round_to: 2) "%.#{round_to}f" % value end |