Module: SEPA::Converter::InstanceMethods

Defined in:
lib/sepa_king/converter.rb

Instance Method Summary collapse

Instance Method Details

#convert_decimal(value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sepa_king/converter.rb', line 38

def convert_decimal(value)
  return unless value
  value = begin
    BigDecimal(value.to_s)
  rescue ArgumentError
  end

  if value && value.finite? && value > 0
    value.round(2)
  end
end

#convert_text(value) ⇒ Object



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

def convert_text(value)
  return unless value

  value.to_s.
    # Replace some special characters described as "Best practices" in Chapter 6.2 of this document:
    # http://www.europeanpaymentscouncil.eu/index.cfm/knowledge-bank/epc-documents/sepa-requirements-for-an-extended-character-set-unicode-subset-best-practices/
    gsub('','E').
    gsub('@','(at)').
    gsub('_','-').

    # Replace linebreaks by spaces
    gsub(/\n+/,' ').

    # Remove all invalid characters
    gsub(/[^a-zA-Z0-9ÄÖÜäöüß&*$%\ \'\:\?\,\-\(\+\.\)\/]/, '').

    # Remove leading and trailing spaces
    strip
end