Class: Stellar::Price
- Inherits:
-
XDR::Struct
- Object
- XDR::Struct
- Stellar::Price
- Defined in:
- lib/stellar/price.rb,
generated/stellar/price.rb
Overview
reopen class
Constant Summary collapse
- MAX_PRECISION =
(2**31) - 1
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_f(number) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/stellar/price.rb', line 8 def self.from_f(number) best_r = Util::ContinuedFraction.best_r(number, MAX_PRECISION) new({ n: best_r.numerator, d: best_r.denominator }) end |
Instance Method Details
#inspect ⇒ Object
28 29 30 |
# File 'lib/stellar/price.rb', line 28 def inspect "#<Stellar::Price #{self}>" end |
#invert ⇒ Object
16 17 18 |
# File 'lib/stellar/price.rb', line 16 def invert self.class.new(n:d,d:n) end |
#to_f ⇒ Object
20 21 22 |
# File 'lib/stellar/price.rb', line 20 def to_f n / d.to_f end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/stellar/price.rb', line 24 def to_s "#{n} / #{d}" end |