Class: LightCurrencyConverter::IndirectCurrencyCourse
- Inherits:
-
Object
- Object
- LightCurrencyConverter::IndirectCurrencyCourse
- Defined in:
- lib/light_currency_convert/indirect_currency_course.rb
Instance Attribute Summary collapse
-
#courses ⇒ Object
Returns the value of attribute courses.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #convert(amount, *args) ⇒ Object
-
#initialize(courses, path) ⇒ IndirectCurrencyCourse
constructor
A new instance of IndirectCurrencyCourse.
- #to_s ⇒ Object
Constructor Details
#initialize(courses, path) ⇒ IndirectCurrencyCourse
Returns a new instance of IndirectCurrencyCourse.
5 6 7 8 |
# File 'lib/light_currency_convert/indirect_currency_course.rb', line 5 def initialize(courses, path) @path = path @courses = courses end |
Instance Attribute Details
#courses ⇒ Object
Returns the value of attribute courses.
3 4 5 |
# File 'lib/light_currency_convert/indirect_currency_course.rb', line 3 def courses @courses end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/light_currency_convert/indirect_currency_course.rb', line 3 def path @path end |
Instance Method Details
#convert(amount, *args) ⇒ Object
10 11 12 13 14 |
# File 'lib/light_currency_convert/indirect_currency_course.rb', line 10 def convert(amount, *args) @courses.zip(path).reduce(amount) do |result, course_with_convert_couple| course_with_convert_couple[0].convert(result, *course_with_convert_couple[1]) end end |
#to_s ⇒ Object
16 17 18 19 20 |
# File 'lib/light_currency_convert/indirect_currency_course.rb', line 16 def to_s flat_path = path.to_a.flatten to_value = convert(1, flat_path[0], flat_path[-1]) "1 #{flat_path[0]} => #{to_value} #{flat_path[-1]}" end |