Module: Ec2spec::Calculator::ApiPriceCalculator

Defined in:
lib/ec2spec/calculator/api_price_calculator.rb

Constant Summary collapse

OXR_CACHE =
'oxr.json'

Instance Method Summary collapse

Instance Method Details

#cache_fileObject



17
18
19
# File 'lib/ec2spec/calculator/api_price_calculator.rb', line 17

def cache_file
  File.join(Ec2spec.project_dir, OXR_CACHE)
end

#currency_unitObject



9
10
11
# File 'lib/ec2spec/calculator/api_price_calculator.rb', line 9

def currency_unit
  @currency_unit
end

#currency_unit_price(dollar_price) ⇒ Object



13
14
15
# File 'lib/ec2spec/calculator/api_price_calculator.rb', line 13

def currency_unit_price(dollar_price)
  Money.new(dollar_price * 100, :USD).exchange_to(currency_unit)
end

#prepare_exchange_api(app_id) ⇒ Object



21
22
23
# File 'lib/ec2spec/calculator/api_price_calculator.rb', line 21

def prepare_exchange_api(app_id)
  prepare_money(app_id)
end

#prepare_money(app_id) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/ec2spec/calculator/api_price_calculator.rb', line 25

def prepare_money(app_id)
  oxr = Money::Bank::OpenExchangeRatesBank.new
  oxr.app_id = app_id
  oxr.cache = cache_file
  oxr.update_rates
  Money.default_bank = oxr
end