Class: LightCurrencyConverter::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/light_currency_convert/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, amount, currecnies) ⇒ Processor

Returns a new instance of Processor.



5
6
7
8
9
10
11
# File 'lib/light_currency_convert/processor.rb', line 5

def initialize(from, to, amount, currecnies)
  @from = from
  @to = to
  @amount = amount
  @currecnies = currecnies
  @course = currecnies.find_currency_course(from, to)
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



3
4
5
# File 'lib/light_currency_convert/processor.rb', line 3

def amount
  @amount
end

#courseObject

Returns the value of attribute course.



3
4
5
# File 'lib/light_currency_convert/processor.rb', line 3

def course
  @course
end

#currenciesObject

Returns the value of attribute currencies.



3
4
5
# File 'lib/light_currency_convert/processor.rb', line 3

def currencies
  @currencies
end

#fromObject

Returns the value of attribute from.



3
4
5
# File 'lib/light_currency_convert/processor.rb', line 3

def from
  @from
end

#toObject

Returns the value of attribute to.



3
4
5
# File 'lib/light_currency_convert/processor.rb', line 3

def to
  @to
end

Instance Method Details

#convertObject

Raises:



19
20
21
22
# File 'lib/light_currency_convert/processor.rb', line 19

def convert
  raise NoCourseFundError unless @course
  @course.convert(amount, from, to)
end

#processObject



13
14
15
16
17
# File 'lib/light_currency_convert/processor.rb', line 13

def process
  amount.nil? ? show_course : convert
rescue NoCourseFundError
  'No course correlation has been found.'
end

#show_courseObject

Raises:



24
25
26
27
# File 'lib/light_currency_convert/processor.rb', line 24

def show_course
  raise NoCourseFundError unless @course
  @course.to_s
end