Class: Ec2spec::PriceCalculator

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ec2spec/price_calculator.rb

Constant Summary collapse

PRICE_CALCULATORS =
{
  manual: Calculator::ManualPriceCalculator,
  api:    Calculator::ApiPriceCalculator,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePriceCalculator

Returns a new instance of PriceCalculator.



19
20
21
22
23
# File 'lib/ec2spec/price_calculator.rb', line 19

def initialize
  @currency_unit = nil
  @dollar_exchange_rate = nil
  @app_id = nil
end

Instance Attribute Details

#currency_unitObject

Returns the value of attribute currency_unit.



12
13
14
# File 'lib/ec2spec/price_calculator.rb', line 12

def currency_unit
  @currency_unit
end

#dollar_exchange_rateObject

Returns the value of attribute dollar_exchange_rate.



12
13
14
# File 'lib/ec2spec/price_calculator.rb', line 12

def dollar_exchange_rate
  @dollar_exchange_rate
end

Instance Method Details

#currency_values?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ec2spec/price_calculator.rb', line 39

def currency_values?
  !@currency_unit.nil?
end

#prepare(unit, rate, calc_type = :manual, app_id = nil) ⇒ Object

Raises:



25
26
27
28
29
30
31
32
33
34
35
36
37
# 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