Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Created September 30, 2018 00:19
Show Gist options
  • Save joegaudet/2dba38b2e994db60d41582d9ab7bc146 to your computer and use it in GitHub Desktop.
Save joegaudet/2dba38b2e994db60d41582d9ab7bc146 to your computer and use it in GitHub Desktop.
class Invoice
%w(sender_details recipient_details).each do |method|
define_method method do
attributes[method]
end
end
%w(total_amount tax_amount).each do |meth|
define_method("#{meth}=") do |value|
currency_config = Invoicing::CurrencyValue::CURRENCIES[currency] || Invoicing::CurrencyValue::CURRENCIES[area.currency]
super(
BigDecimal(value).round(
currency_config[:digits],
Money.rounding_mode
)
)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment