![]() Now all that's left is somehow calling the rates.json file and comparing the user inputs to the existing data. So I managed to use the gets and put functions. I think I have to use a put and a get to capture the user date input? Then the same for each of the two currencies? Of course, my syntax for the date stuff is all wrong. Puts "USD to GBP: #"ĭef self.rate(input_date, input_curr_1, input_curr_2) Test_Exchange.rb: require_relative 'Exchange.rb' Rates = u/rates # get rates of given dayįrom_to_eur = 1.0 / rates # convert to EURįrom_to_eur * rates # convert to target currency Choose from 345 world currencies by name, code, country or use smart search. # Raises an exception if there is no rate for the date = JSON.parse(File.read('rates.json'))ĭef self.rate(date, from_currency, to_currency) # Raises an exception if unable to calculate requested rate. # Return the exchange rate between from_currency and to_currency on date as a float. So far I have 3 files ( Exchange.rb, Test_Exchange.rb, rates.json): The test data is in EUR, so all rates are converted to EUR and then to the target currency. I have a data file containing test data (date, currency from, currency to). This could result in the recipient receiving less than the amount you originally sent.I'm trying to create a currency converter in Ruby which will calculate the exchange rate between two currencies on a given date.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |