Support for historical exchange rates
Hi,
It'll be nice if the exchange_to method in money/money.rb and the exchange_with method in money/bank/base.rb took an optional Date parameter (that defaults to Date.today).
I'm aware that there is a money-historical-bank gem which has a custom bank.exchange_with method. Do you think it is a good idea to include an optional Date parameter within the core money infrastructure so that we can make use of the methods there? (e.g. arithmetic)
For example,
a = "1 USD".to_money
b = "1 GBP".to_money
a.+(b, Date.yesterday)
instead of
a = "1 USD".to_money
b = "1 GBP".to_money
bank = Money::Bank::VariableExchange.new
# ... add exchange rates here
a + bank.exchange_with(Date.yesterday, b, "USD")
Do you have plans to support this feature? If not, and if you are supportive of adding it, I can look into it.
Sounds cool but in my opinion as it's not really fundamental money functionality and probably only relevant for few projects, I'd say it sounds like sth. to go into a to-be-created money-ext gem or so.
My opinion is similar to @marcoow's - if you are using this gem in production in real world (everything which is fiscal), the historical rates are often required. So making this as an extension is perfect compromise. For me big :+1:
Since historical rates are often required, wouldn't it make sense to include it in the core infrastructure of the money gem?
The problem with creating a money extension gem is that a lot of the methods (such as in arithmetic) will have to be re-written with a lot of repetition. They'll have to be constantly re-synced whenever there is a new money gem release.
Sorry, I somehow misread your original post - thought the proposal was to add the #exchange_with method to the money gem. I think adding an additional parameter to the + operator is not such a great idea actually as it's kind of a surprising syntax and not really necessary as it only saves a few lines...
I'd say it would be much better syntax if you e.g. had sth. like this (also with this solution there would be no duplication in a hypothetical money-ext gem):
a = "1 USD".to_money
b = "1 GBP".to_money
a + b.at(Date.yesterday, 'USD')
I agree with @marcoow that his solution would be preferred. This should be an extension most definitely. I'd have not problem rolling it under the RubyMoney org though to make sure it gets love from the community.
@marcoow that's way better syntax! @semmons99 thanks. It'll probably make sense to patch the historical bank gem? I'll look into it.
@yinquanteo yeah.