Module: SPS::Converter::InstanceMethods
- Defined in:
- lib/sps_king/converter.rb
Instance Method Summary collapse
-
#convert_decimal(value) ⇒ BigDecimal|nil
The converted value or nil if the conversion failed.
- #convert_text(value) ⇒ Object
Instance Method Details
#convert_decimal(value) ⇒ BigDecimal|nil
Returns the converted value or nil if the conversion failed.
45 46 47 48 49 50 51 52 |
# File 'lib/sps_king/converter.rb', line 45 def convert_decimal(value) val = begin BigDecimal(value.to_s) rescue ArgumentError nil end val.round(2) if val&.finite? && val > 0 end |
#convert_text(value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sps_king/converter.rb', line 23 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 |