Module: SEPA::Converter::InstanceMethods

Defined in:
lib/sepa_rator/converter.rb

Instance Method Summary collapse

Instance Method Details

#convert_decimal(value) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/sepa_rator/converter.rb', line 35

def convert_decimal(value)
  return unless value

  value = BigDecimal(value.to_s, exception: false)

  return unless value&.finite? && value.positive?

  value.round(2)
end

#convert_text(value) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sepa_rator/converter.rb', line 19

def convert_text(value)
  return unless value

  # Replace special characters (EPC Best Practices, Chapter 6.2)
  # http://www.europeanpaymentscouncil.eu/index.cfm/knowledge-bank/epc-documents/sepa-requirements-for-an-extended-character-set-unicode-subset-best-practices/
  value.to_s
       .encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
       .tr('', 'E')
       .gsub('@', '(at)')
       .tr('_', '-')
       .tr('&', '+')
       .gsub(/\n+/, ' ')
       .gsub(%r{[^a-zA-Z0-9\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F ':?,\-(+.)/]}, '')
       .strip
end