Module: Secretariat::Helpers
- Defined in:
- lib/secretariat/helpers.rb
Class Method Summary collapse
- .currency_element(xml, ns, name, amount, currency, add_currency: true, digits: 2) ⇒ Object
- .format(something, round: nil, digits: 2) ⇒ Object
Class Method Details
.currency_element(xml, ns, name, amount, currency, add_currency: true, digits: 2) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/secretariat/helpers.rb', line 9 def self.currency_element(xml, ns, name, amount, currency, add_currency: true, digits: 2) attrs = {} if add_currency attrs[:currencyID] = currency end xml[ns].send(name, attrs) do xml.text(format(amount, round: 4, digits: digits)) end end |
.format(something, round: nil, digits: 2) ⇒ Object
3 4 5 6 7 |
# File 'lib/secretariat/helpers.rb', line 3 def self.format(something, round: nil, digits:2) dec = BigDecimal(something, 10) dec = dec.round(round, :down) if round "%0.#{digits}f" % dec end |