class Ec2spec::PriceCalculator

Constants

PRICE_CALCULATORS

Attributes

currency_unit[RW]
dollar_exchange_rate[RW]

Public Class Methods

new() click to toggle source
# File lib/ec2spec/price_calculator.rb, line 19
def initialize
  @currency_unit = nil
  @dollar_exchange_rate = nil
  @app_id = nil
end

Public Instance Methods

currency_values?() click to toggle source
# File lib/ec2spec/price_calculator.rb, line 39
def currency_values?
  !@currency_unit.nil?
end
prepare(unit, rate, calc_type = :manual, app_id = nil) click to toggle source
# File lib/ec2spec/price_calculator.rb, line 25
def prepare(unit, rate, calc_type = :manual, app_id = nil)
  @currency_unit = unit
  @dollar_exchange_rate = rate
  @app_id = app_id
  @calc_type = calc_type

  extend_calc

  Money.infinite_precision = true
  raise ApiKeyError if calc_type_sym == :api && app_id.nil?
  prepare_exchange_api(app_id) if calc_type_sym == :api
  self
end

Private Instance Methods

calc_type_sym() click to toggle source
# File lib/ec2spec/price_calculator.rb, line 51
def calc_type_sym
  @calc_type.to_sym
rescue NoMethodError
  raise UndefinedCalcError
end
extend_calc() click to toggle source
# File lib/ec2spec/price_calculator.rb, line 45
def extend_calc
  raise UndefinedCalcError unless PRICE_CALCULATORS.key?(calc_type_sym)
  extend PRICE_CALCULATORS[calc_type_sym]
  Ec2spec.logger.debug("Calculate price: #{@calc_type}")
end