Sha256: 0fcd9e39c594d45957f46a36987ac0ae17dd1fe69e1e1d608d35c71adaaa29a4

Contents?: true

Size: 469 Bytes

Versions: 48

Compression:

Stored size: 469 Bytes

Contents

module Stellar

  # reopen class
  class Price

    MAX_PRECISION = (2**31) - 1

    def self.from_f(number)
      best_r = Util::ContinuedFraction.best_r(number, MAX_PRECISION)
      new({
        n: best_r.numerator,
        d: best_r.denominator
      })
    end

    def invert
      self.class.new(n:d,d:n)
    end

    def to_f
      n / d.to_f
    end

    def to_s
      "#{n} / #{d}"
    end

    def inspect
      "#<Stellar::Price #{self}>"
    end
  end
end

Version data entries

48 entries across 48 versions & 3 rubygems

Version Path
stellar-base-0.22.0 lib/stellar/price.rb
stellar-base-0.21.0 lib/stellar/price.rb
stellar-base-0.20.0 lib/stellar/price.rb
stellar-base-0.19.0 lib/stellar/price.rb
stellar-base-0.18.0 lib/stellar/price.rb
stellar-base-0.17.0 lib/stellar/price.rb
stellar-base-0.16.0 lib/stellar/price.rb
stellar-base-0.15.0 lib/stellar/price.rb
stellar-base-0.14.0 lib/stellar/price.rb
stellar-base-0.13.0 lib/stellar/price.rb
stellar-base-0.12.0 lib/stellar/price.rb
stellar-base-0.11.0 lib/stellar/price.rb
auction-ruby-base-0.1.3 lib/stellar/price.rb
auction-ruby-base-0.1.2 lib/stellar/price.rb
auction-ruby-base-0.1.1 lib/stellar/price.rb
stellar-base-0.10.0 lib/stellar/price.rb
stellar-base-0.9.0 lib/stellar/price.rb
stellar-base-0.8.0 lib/stellar/price.rb
stellar-base-0.7.0 lib/stellar/price.rb
stellar-base-0.6.1 lib/stellar/price.rb