cmxl 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.mdown +10 -4
- data/README.md +19 -2
- data/lib/cmxl.rb +5 -2
- data/lib/cmxl/statement.rb +8 -0
- data/lib/cmxl/version.rb +1 -1
- data/spec/fixtures/mt940-headers.txt +11 -0
- data/spec/mt940_parsing_spec.rb +12 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afe5eaa1a3c99146e56b607756e95dd8bcf51685e68664030b7c404be70807cd
|
4
|
+
data.tar.gz: da2779f99da9caa20e48ec6fefd1beb0b399e5643f2491c30df1f3dbb6b32c8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc07aeb371d965613da239f77c5eb392f3d0d24c45978446b2658de88a3962a1caef0b620bf20424fd68712b78e25e5301d0a543f9cae02ad4e3a082e9e704f0
|
7
|
+
data.tar.gz: d88efb472d1df7a613651af9c71b81953a5ad32f4fc09caeea3d6f51e2e5c88a6dda5b69e7bbadfcfc4a6fd1a68b6e040ba88452dc0b0499005f635a33e6a04f
|
data/CHANGELOG.mdown
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
+
# 1.2.0
|
2
|
+
* [FEATURE] strips mt940 header if configured ([#9](https://github.com/railslove/cmxl/issues/9))
|
3
|
+
```ruby
|
4
|
+
Cmxl.config[:strip_headers] = true
|
5
|
+
```
|
6
|
+
|
1
7
|
# 1.1.1
|
2
8
|
* [BUGFIX] prevents short bank references from swallowing supplementary details delimiter
|
3
9
|
|
4
10
|
# 1.1.0
|
5
|
-
* [FEATURE] adds support for supplementary details in transactions (Field 61, Subfield 9) (#18)
|
11
|
+
* [FEATURE] adds support for supplementary details in transactions (Field 61, Subfield 9) ([#18](https://github.com/railslove/cmxl/issues/18))
|
6
12
|
|
7
13
|
# 1.0.0
|
8
|
-
* [FEATURE] adds support for storno transactions (#14)
|
14
|
+
* [FEATURE] adds support for storno transactions ([#14](https://github.com/railslove/cmxl/issues/14))
|
9
15
|
* [NOTE] full backwards compatibility
|
10
16
|
* [NOTE] same as release 0.2.2, fixing versioning
|
11
17
|
|
@@ -16,8 +22,8 @@
|
|
16
22
|
* MT942 support for field 13
|
17
23
|
|
18
24
|
# 0.2.0
|
19
|
-
* added several balance related accessors (#7)
|
20
|
-
* configuration option for `statement separator` (#5)
|
25
|
+
* added several balance related accessors ([#7](https://github.com/railslove/cmxl/issues/7))
|
26
|
+
* configuration option for `statement separator` ([#5](https://github.com/railslove/cmxl/issues/5))
|
21
27
|
* improvement for general compatibility
|
22
28
|
|
23
29
|
# 0.1.3
|
data/README.md
CHANGED
@@ -42,12 +42,17 @@ Simple usage:
|
|
42
42
|
```ruby
|
43
43
|
|
44
44
|
# Configuration:
|
45
|
-
# Cmxl currently allows you to configure the statement divider - though the default should be good in most of the cases
|
46
|
-
# and you can configure if line parsing errors should be raised
|
47
45
|
|
46
|
+
# statement divider regex to split the individual statements in one file - the default is standard and should be good for most files
|
48
47
|
Cmxl.config[:statement_separator] = /\n-.\n/m
|
48
|
+
|
49
|
+
# do you want an error to be raised when a line can not be parsed? default is true
|
49
50
|
Cmxl.config[:raise_line_format_errors] = true
|
50
51
|
|
52
|
+
# try to stip the SWIFT header data. This strips everything until the actual first MT940 field. (if parsing fails try this!)
|
53
|
+
Cmxl.config[:strip_headers] = true
|
54
|
+
|
55
|
+
|
51
56
|
# Statment parsing:
|
52
57
|
|
53
58
|
statements = Cmxl.parse(File.read('mt940.txt'), :encoding => 'ISO-8859-1') # parses the file and returns an array of statement objects. Please note: if no encoding is given Cmxl tries to guess the encoding from the content and converts it to UTF-8.
|
@@ -87,6 +92,16 @@ We try to handle encoding and format wirednesses as much as possible. If no enco
|
|
87
92
|
In the likely case that you encouter encoding issues you can pass encoding options to the `Cmxl.parse(<string>, <options hash>)` it accepts the same options as [String#encode](http://ruby-doc.org/core-2.1.3/String.html#method-i-encode)
|
88
93
|
If that fails try to motify the file before you pass it to the parser - and please create an issue.
|
89
94
|
|
95
|
+
### MT940 SWIFT header data
|
96
|
+
|
97
|
+
Cmxl currently does not support parsing of the SWIFT headers (like {1:F01AXISINBBA ....)
|
98
|
+
If your file comes with these headers try the `strip_headers` configuration option to strip data execpt the actual MT940 fields.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
Cmxl.config[:strip_headers] = true
|
102
|
+
Cmxl.parse(...)
|
103
|
+
```
|
104
|
+
|
90
105
|
### Custom field parsers
|
91
106
|
|
92
107
|
Because a lot of banks implement the MT940 format slightly different one of the design goals of this library is to be able to customize the individual field parsers.
|
@@ -120,6 +135,8 @@ If you have a file that can not be parsed please open an issue. We hope to build
|
|
120
135
|
## ToDo
|
121
136
|
|
122
137
|
* collect MT940 files from different banks and use them as example for specs
|
138
|
+
* support for Mt942
|
139
|
+
* better header data handling
|
123
140
|
|
124
141
|
|
125
142
|
## Looking for other Banking and EBICS tools?
|
data/lib/cmxl.rb
CHANGED
@@ -10,7 +10,11 @@ module Cmxl
|
|
10
10
|
def self.config
|
11
11
|
@config
|
12
12
|
end
|
13
|
-
@config = {
|
13
|
+
@config = {
|
14
|
+
:statement_separator => /\n-\s*\n/m,
|
15
|
+
:raise_line_format_errors => true,
|
16
|
+
:strip_headers => false
|
17
|
+
}
|
14
18
|
|
15
19
|
# Public: Parse a MT940 string
|
16
20
|
#
|
@@ -25,7 +29,6 @@ module Cmxl
|
|
25
29
|
#
|
26
30
|
# Returns an array of Statement objects
|
27
31
|
def self.parse(data, options={})
|
28
|
-
options[:universal_newline] ||= true
|
29
32
|
options[:statement_separator] ||= self.config[:statement_separator]
|
30
33
|
# if no encoding is provided we try to guess using CharDet
|
31
34
|
if options[:encoding].nil? && cd = CharDet.detect(data, silent: true)
|
data/lib/cmxl/statement.rb
CHANGED
@@ -13,6 +13,7 @@ module Cmxl
|
|
13
13
|
self.source = source
|
14
14
|
self.fields = []
|
15
15
|
self.lines = []
|
16
|
+
self.strip_headers! if Cmxl.config[:strip_headers]
|
16
17
|
self.parse!
|
17
18
|
end
|
18
19
|
|
@@ -42,6 +43,13 @@ module Cmxl
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
46
|
+
def strip_headers!
|
47
|
+
self.source.gsub!(/\A.+?(?=^:)/m, '') # beginning: strip every line in the beginning that does not start with a :
|
48
|
+
self.source.gsub!(/^[^:]+\z/, '') # end: strip every line in the end that does not start with a :
|
49
|
+
self.source.strip!
|
50
|
+
end
|
51
|
+
|
52
|
+
|
45
53
|
# Public: SHA2 of the provided source
|
46
54
|
# This is an experiment of trying to identify statements. The MT940 itself might not provide a unique identifier
|
47
55
|
#
|
data/lib/cmxl/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
{1:D02AASDISLNETAXXXXXXXXXXXXX}
|
2
|
+
{2:E623XXXXXXXXAXXXN}
|
3
|
+
{4:
|
4
|
+
:20:MT940/78374
|
5
|
+
:25:xxxxxxxxxxxxxx
|
6
|
+
:28C:3/1
|
7
|
+
:60F:C160201INR0,00
|
8
|
+
:61:3622687806CR1368378,92NMSC37935531
|
9
|
+
:86:-TX TRN-REF NO.1156ADS5601187 EUR 13456/TSV
|
10
|
+
:62F:C141387INR11 27421,94
|
11
|
+
-}
|
data/spec/mt940_parsing_spec.rb
CHANGED
@@ -75,4 +75,16 @@ describe 'parsing a statement' do
|
|
75
75
|
expect(subject.size).to eq(3)
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
describe 'MT940 with headers' do
|
80
|
+
before { Cmxl.config[:strip_headers] = true }
|
81
|
+
after { Cmxl.config[:strip_headers] = false }
|
82
|
+
subject { Cmxl.parse(mt940_file('mt940-headers')) }
|
83
|
+
|
84
|
+
it { expect(subject.count).to eql(1) }
|
85
|
+
|
86
|
+
it 'parses the statement without problems' do
|
87
|
+
expect(subject[0].transactions.count).to eql(1)
|
88
|
+
end
|
89
|
+
end
|
78
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmxl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bumann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- spec/fixtures/lines/statement_supplementary_complex.txt
|
155
155
|
- spec/fixtures/lines/statement_supplementary_plain.txt
|
156
156
|
- spec/fixtures/mt940-deutsche_bank.txt
|
157
|
+
- spec/fixtures/mt940-headers.txt
|
157
158
|
- spec/fixtures/mt940-iso8859-1.txt
|
158
159
|
- spec/fixtures/mt940-with-detailed-end-balance.txt
|
159
160
|
- spec/fixtures/mt940.txt
|
@@ -219,6 +220,7 @@ test_files:
|
|
219
220
|
- spec/fixtures/lines/statement_supplementary_complex.txt
|
220
221
|
- spec/fixtures/lines/statement_supplementary_plain.txt
|
221
222
|
- spec/fixtures/mt940-deutsche_bank.txt
|
223
|
+
- spec/fixtures/mt940-headers.txt
|
222
224
|
- spec/fixtures/mt940-iso8859-1.txt
|
223
225
|
- spec/fixtures/mt940-with-detailed-end-balance.txt
|
224
226
|
- spec/fixtures/mt940.txt
|