Module: Ask::Tokens::Pricing
- Defined in:
- lib/ask/tokens/pricing.rb
Overview
Class Method Summary collapse
-
.cents_for(count, currency: nil) ⇒ Object
The price of
counttokens in the currency's minor units (cents). -
.price_of(count) ⇒ Object
Price of
counttokens at the configured rate. -
.tokens_for(money) ⇒ Object
How many billing tokens a Money (or numeric dollar) amount buys.
Class Method Details
.cents_for(count, currency: nil) ⇒ Object
The price of count tokens in the currency's minor units (cents).
35 36 37 |
# File 'lib/ask/tokens/pricing.rb', line 35 def cents_for(count, currency: nil) price_of(count).cents.to_i end |
.price_of(count) ⇒ Object
22 23 24 |
# File 'lib/ask/tokens/pricing.rb', line 22 def price_of(count) Ask::Tokens.config.price_per_token * count.to_i end |
.tokens_for(money) ⇒ Object
How many billing tokens a Money (or numeric dollar) amount buys.
27 28 29 30 31 32 |
# File 'lib/ask/tokens/pricing.rb', line 27 def tokens_for(money) amount = money.is_a?(Money) ? money : Money.from_amount(money.to_d, Ask::Tokens.config.currency) return 0 if amount.negative? || amount.zero? (amount / Ask::Tokens.config.price_per_token).to_i end |