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
- .config ⇒ Object
-
.parse(data, options = {}) ⇒ Object
Public: Parse a MT940 string.
Class Method Details
.config ⇒ Object
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, = {}) [:statement_separator] ||= config[:statement_separator] # if no encoding is provided we try to guess using CharDet if [:encoding].nil? && cd = CharDet.detect(data) [:encoding] = cd['encoding'] end if [:encoding] data.encode!('UTF-8', .delete(:encoding), **) else data.encode!('UTF-8', **) unless .empty? end data.split([:statement_separator]).reject { |s| s.strip.empty? }.collect { |s| Cmxl::Statement.new(s.strip) } end |