Module: Secretariat::Helpers

Defined in:
lib/secretariat/helpers.rb

Class Method Summary collapse

Class Method Details

.currency_element(xml, ns, name, amount, currency, add_currency: true, digits: 2) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/secretariat/helpers.rb', line 24

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

.date_element(xml, date) ⇒ Object



34
35
36
37
38
39
# File 'lib/secretariat/helpers.rb', line 34

def self.date_element(xml, date)
  date = date.strftime("%Y%m%d") if date.respond_to?(:strftime)
  xml['udt'].DateTimeString(format: '102') do
    xml.text(date)
  end
end

.format(something, round: nil, digits: 2) ⇒ Object



18
19
20
21
22
# File 'lib/secretariat/helpers.rb', line 18

def self.format(something, round: nil, digits:2)
  dec = BigDecimal(something, 10)
  dec = dec.round(round, :down) if round
  "%0.#{digits}f" % dec
end