Class: Moneyc::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/moneyc/converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(from:, to: nil, at: nil) ⇒ Converter

Returns a new instance of Converter.


3
4
5
6
7
# File 'lib/moneyc/converter.rb', line 3

def initialize(from:, to: nil, at: nil)
  @reference_currency = from
  @target_currency = presence(to) || @reference_currency
  @conversion_date = presence(at) || Time.now
end

Instance Method Details

#convert(total_in_reference_currency) ⇒ Object


17
18
19
# File 'lib/moneyc/converter.rb', line 17

def convert(total_in_reference_currency)
  total_in_reference_currency.to_f * rate
end

#rateObject


9
10
11
12
13
14
15
# File 'lib/moneyc/converter.rb', line 9

def rate
  if reference_and_target_is_same?
    1
  else
    retrieve_taget_currency_rate
  end
end