class Stellar::Price
reopen class
Constants
- MAX_PRECISION
Public Class Methods
from_f(number)
click to toggle source
# File lib/stellar/price.rb, line 6 def self.from_f(number) best_r = number.to_r.rationalize(1.0e-7) if best_r.numerator > MAX_PRECISION || best_r.denominator > MAX_PRECISION raise ArgumentError("Couldn't find price approximation") end new({ n: best_r.numerator, d: best_r.denominator }) end
Public Instance Methods
inspect()
click to toggle source
# File lib/stellar/price.rb, line 35 def inspect "#<Stellar::Price #{self}>" end
invert()
click to toggle source
# File lib/stellar/price.rb, line 19 def invert self.class.new(n: d, d: n) end
to_d()
click to toggle source
# File lib/stellar/price.rb, line 23 def to_d n.to_d / d end
to_f()
click to toggle source
# File lib/stellar/price.rb, line 27 def to_f n.to_f / d end
to_s()
click to toggle source
# File lib/stellar/price.rb, line 31 def to_s "#{n} / #{d}" end