Module: Cmxl

Defined in:
lib/cmxl.rb,
lib/cmxl/field.rb,
lib/cmxl/version.rb,
lib/cmxl/statement.rb,
lib/cmxl/fields/reference.rb,
lib/cmxl/fields/entry_date.rb,
lib/cmxl/fields/transaction.rb,
lib/cmxl/fields/vmk_summary.rb,
lib/cmxl/fields/account_balance.rb,
lib/cmxl/fields/closing_balance.rb,
lib/cmxl/fields/statement_number.rb,
lib/cmxl/fields/available_balance.rb,
lib/cmxl/fields/statement_details.rb,
lib/cmxl/fields/floor_limit_indicator.rb,
lib/cmxl/fields/account_identification.rb,
lib/cmxl/fields/transaction_supplementary.rb

Defined Under Namespace

Modules: Fields Classes: Field, Statement

Constant Summary collapse

VERSION =
'2.2'.freeze

Class Method Summary collapse

Class Method Details

.configObject



10
11
12
# File 'lib/cmxl.rb', line 10

def self.config
  @config
end

.parse(data, options = {}) ⇒ Object

Public: Parse a MT940 string

data - The String containing the MT940 options - Hash with encoding options. Accepts the same parameters as String#encode!

It is likely that you want to provide the encoding of your MT940 String

Examples

Cmxl.parse(File.read(‘mt940.txt’), encoding: ‘ISO-8859-1’) Cmxl.parse(mt940_string)

Returns an array of Statement objects



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cmxl.rb', line 35

def self.parse(data, options = {})
  options[:statement_separator] ||= config[:statement_separator]
  # if no encoding is provided we try to guess using CharDet
  if options[:encoding].nil? && cd = CharDet.detect(data)
    options[:encoding] = cd['encoding']
  end

  if options[:encoding]
    data.encode!('UTF-8', options.delete(:encoding), **options)
  else
    data.encode!('UTF-8', **options) unless options.empty?
  end

  data.split(options[:statement_separator]).reject { |s| s.strip.empty? }.collect { |s| Cmxl::Statement.new(s.strip) }
end