To set up and run the solution, follow these steps:
- Ensure Ruby is installed on your system. The code has been tested with Ruby 2.7.0, but it should work with newer versions as well.
- Place the
currency_exchange.rb
file and thedata
directory containing theeurofxref-hist-90d.json
file in the same directory. - Run the program from the terminal with the command
ruby currency_exchange.rb
. - Follow the interactive prompts in the terminal to enter the date and currency codes you wish to exchange.
-
Data Source Abstraction The code is designed with a
DataSource
abstraction that allows for different data sources to be plugged into the system. The current implementation uses aJSONDataSource
class that reads exchange rates from a JSON file. -
Currency Exchange Calculation The
CurrencyExchange
class is responsible for calculating exchange rates. It is designed to work with any data source that conforms to the interface defined by theDataSource
abstraction. -
Extensibility for Future Data Sources The system is designed to be easily extended to support other data formats or sources, such as XML, CSV, or even live APIs. New data source classes can be created by inheriting from
DataSource
and implementing theload_data
method. -
Interactive Terminal Interface The user interacts with the system through an interactive terminal interface, which guides them through the process of retrieving exchange rates. It is designed to be user-friendly and to handle invalid input gracefully.
-
Error Handling The code includes robust error handling to guide users back to the correct input path if they enter data that is out of range or otherwise invalid. The goal is to provide a seamless experience that does not punish users for mistakes.