cmxl 2.1 → 2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.mdown +5 -0
- data/README.md +39 -20
- data/lib/cmxl/fields/statement_details.rb +1 -1
- data/lib/cmxl/statement.rb +0 -1
- data/lib/cmxl/version.rb +1 -1
- data/lib/cmxl.rb +1 -1
- data/spec/fields/statement_details_spec.rb +41 -0
- data/spec/statement_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7d3b16a51915ab4abdd146b5f213b4957392ace7f27be151fbc253ea820dd6c
|
4
|
+
data.tar.gz: cc398d5bd6fb2e112abfa815de950fd34a300107ba573b50ea8fb9ed98703f23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c9d4c881bc2f1f644471bf24a5c2f0c0fdc0543f828ba82e2960f1a015d397f10cdbc74d5fece4f79f2638625000ba8f8e80d0bbfa7ead01aec2b09992ff940
|
7
|
+
data.tar.gz: 2ba29e61b1060f43ddc7699211ff109064256366e18089a1d46b41b513906fabbb60ca12a74d322595f6ef726ea9068150829d0e0c5c4c3d2c7c690a0aeef309
|
data/CHANGELOG.mdown
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# NEXT release
|
2
2
|
|
3
|
+
# 2.2
|
4
|
+
- `[ENHANCEMENT]` enable `strip_headers` option per default.
|
5
|
+
- `[BUGFIX]` fix `strip_header` remove greedy regex logic
|
6
|
+
- `[BUGFIX]` support details parsing from files on windows os
|
7
|
+
|
3
8
|
# 2.1
|
4
9
|
- `[REFACTOR]` improve file parser to work with windows line breaks and any known header formats
|
5
10
|
- `[BUGFIX]` fix `strip_header` making it work on statements without headers
|
data/README.md
CHANGED
@@ -38,25 +38,11 @@ Or install it yourself as:
|
|
38
38
|
|
39
39
|
## Usage
|
40
40
|
|
41
|
-
Simple usage:
|
41
|
+
### Simple usage:
|
42
42
|
|
43
43
|
```ruby
|
44
|
+
statements = Cmxl.parse(File.read('mt940.txt'))
|
44
45
|
|
45
|
-
# Configuration:
|
46
|
-
|
47
|
-
# statement divider regex to split the individual statements in one file - the default is standard and should be good for most files
|
48
|
-
Cmxl.config[:statement_separator] = /\n-.\n/m
|
49
|
-
|
50
|
-
# do you want an error to be raised when a line can not be parsed? default is true
|
51
|
-
Cmxl.config[:raise_line_format_errors] = true
|
52
|
-
|
53
|
-
# try to stip the SWIFT header data. This strips everything until the actual first MT940 field. (if parsing fails, try this!)
|
54
|
-
Cmxl.config[:strip_headers] = true
|
55
|
-
|
56
|
-
|
57
|
-
# Statment parsing:
|
58
|
-
|
59
|
-
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.
|
60
46
|
statements.each do |s|
|
61
47
|
puts s.reference
|
62
48
|
puts s.generation_date
|
@@ -81,25 +67,58 @@ statements.each do |s|
|
|
81
67
|
# ...
|
82
68
|
end
|
83
69
|
end
|
84
|
-
|
85
70
|
```
|
86
71
|
|
87
72
|
Every object responds to `to_h` and let's you easily convert the data to a hash. Also every object responds to `to_json` which lets you easily represent the statements as JSON with your favorite JSON library.
|
88
73
|
|
89
|
-
|
74
|
+
### File encoding options
|
90
75
|
|
91
76
|
You probably will encounter encoding issues (hey, you are building banking applications!).
|
92
77
|
We try to handle encoding and format weirdnesses as much as possible. If no encoding is passed we try to guess the encoding of the data and convert it to UTF8.
|
93
78
|
In the likely case that you encounter encoding issues you can pass encoding options to `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)
|
94
79
|
If that fails, try to modify the file before you pass it to the parser - and please create an issue.
|
95
80
|
|
96
|
-
|
81
|
+
```ruby
|
82
|
+
Cmxl.parse(File.read('mt940.txt'), :encoding => 'ISO-8859-1')
|
83
|
+
```
|
84
|
+
|
85
|
+
## Global configurations:
|
86
|
+
The gem offers option to adjust behavior for the gem
|
87
|
+
|
88
|
+
### `statement_separator`
|
89
|
+
statement divider regex to split the individual statements in one file
|
90
|
+
|
91
|
+
|type|default|
|
92
|
+
|----|-------|
|
93
|
+
|regex|[`/\R+-[^\n\r]*\R*/m`](https://github.com/railslove/cmxl/blob/main/lib/cmxl.rb#L18)|
|
97
94
|
|
95
|
+
```ruby
|
96
|
+
Cmxl.config[:statement_separator] = ...
|
97
|
+
Cmxl.parse(...)
|
98
|
+
```
|
99
|
+
|
100
|
+
### `raise_line_format_errors`
|
101
|
+
do you want an error to be raised when a line can not be parsed?
|
102
|
+
|
103
|
+
|type|default|
|
104
|
+
|----|-------|
|
105
|
+
|boolean|[`true`](https://github.com/railslove/cmxl/blob/main/lib/cmxl.rb#L19)|
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Cmxl.config[:raise_line_format_errors] = ...
|
109
|
+
Cmxl.parse(...)
|
110
|
+
```
|
111
|
+
|
112
|
+
### `strip_headers`
|
98
113
|
Cmxl currently does not support parsing of the SWIFT headers (like {1:F01AXISINBBA ....)
|
99
114
|
If your file comes with these headers try the `strip_headers` configuration option to strip data except the actual MT940 fields.
|
100
115
|
|
116
|
+
|type|default|
|
117
|
+
|----|-------|
|
118
|
+
|boolean|[`false`](https://github.com/railslove/cmxl/blob/main/lib/cmxl.rb#L20)|
|
119
|
+
|
101
120
|
```ruby
|
102
|
-
Cmxl.config[:strip_headers] =
|
121
|
+
Cmxl.config[:strip_headers] = ...
|
103
122
|
Cmxl.parse(...)
|
104
123
|
```
|
105
124
|
|
data/lib/cmxl/statement.rb
CHANGED
@@ -42,7 +42,6 @@ module Cmxl
|
|
42
42
|
|
43
43
|
def strip_headers!
|
44
44
|
source.gsub!(/\A.*?(?=^:)/m, '') # beginning: strip every line in the beginning that does not start with a :
|
45
|
-
source.gsub!(/^[^:]*\z/, '') # end: strip every line in the end that does not start with a :
|
46
45
|
source.strip!
|
47
46
|
end
|
48
47
|
|
data/lib/cmxl/version.rb
CHANGED
data/lib/cmxl.rb
CHANGED
@@ -17,7 +17,7 @@ module Cmxl
|
|
17
17
|
# \R is a platform independent newline but in the negated group `[^\n\r]` that did not seem to work.
|
18
18
|
statement_separator: /\R+-[^\n\r]*\R*/m,
|
19
19
|
raise_line_format_errors: true,
|
20
|
-
strip_headers:
|
20
|
+
strip_headers: true
|
21
21
|
}
|
22
22
|
|
23
23
|
# Public: Parse a MT940 string
|
@@ -75,6 +75,47 @@ describe Cmxl::Fields::StatementDetails do
|
|
75
75
|
)
|
76
76
|
}
|
77
77
|
it { expect(subject.to_hash).to eql(subject.to_h) }
|
78
|
+
|
79
|
+
context 'with newlines in windows format' do
|
80
|
+
it 'removes any newlines' do
|
81
|
+
data = ":86:171?00SEPA LASTSCHRIFT KUNDE?10281?\r\n20KREF+EREF+TRX-0A4A47C3-F846-4729?21-8A1B-5DF620F?22MREF+CAC97D2144174318AC18D9?23BF815BD4FB?24CRED+DE98ZZZ09999999999?25SVWZ+FOO TRX-0A4A47C3-F84?266-4729-8A1B-5DF620F?30HYVEDEMMXXX?31HUkkbbbsssskcccccccccccccccx?\r\n32Peter Pan?99?34171"
|
82
|
+
result = Cmxl::Fields::StatementDetails.parse(data)
|
83
|
+
|
84
|
+
expect(result.to_h).to eql(
|
85
|
+
'bic' => 'HYVEDEMMXXX',
|
86
|
+
'iban' => 'HUkkbbbsssskcccccccccccccccx',
|
87
|
+
'name' => 'Peter Pan',
|
88
|
+
'sepa' => {
|
89
|
+
'KREF' => '',
|
90
|
+
'EREF' => 'TRX-0A4A47C3-F846-4729-8A1B-5DF620F',
|
91
|
+
'MREF' => 'CAC97D2144174318AC18D9BF815BD4FB',
|
92
|
+
'CRED' => 'DE98ZZZ09999999999',
|
93
|
+
'SVWZ' => 'FOO TRX-0A4A47C3-F846-4729-8A1B-5DF620F'
|
94
|
+
},
|
95
|
+
'information' => 'KREF+EREF+TRX-0A4A47C3-F846-4729-8A1B-5DF620FMREF+CAC97D2144174318AC18D9BF815BD4FBCRED+DE98ZZZ09999999999SVWZ+FOO TRX-0A4A47C3-F846-4729-8A1B-5DF620F',
|
96
|
+
'description' => 'SEPA LASTSCHRIFT KUNDE',
|
97
|
+
'sub_fields' => {
|
98
|
+
'00' => 'SEPA LASTSCHRIFT KUNDE',
|
99
|
+
'10' => '281',
|
100
|
+
'20' => 'KREF+EREF+TRX-0A4A47C3-F846-4729',
|
101
|
+
'21' => '-8A1B-5DF620F',
|
102
|
+
'22' => 'MREF+CAC97D2144174318AC18D9',
|
103
|
+
'23' => 'BF815BD4FB',
|
104
|
+
'24' => 'CRED+DE98ZZZ09999999999',
|
105
|
+
'25' => 'SVWZ+FOO TRX-0A4A47C3-F84',
|
106
|
+
'26' => '6-4729-8A1B-5DF620F',
|
107
|
+
'30' => 'HYVEDEMMXXX',
|
108
|
+
'31' => 'HUkkbbbsssskcccccccccccccccx',
|
109
|
+
'32' => 'Peter Pan',
|
110
|
+
'34' => '171',
|
111
|
+
'99' => ''
|
112
|
+
},
|
113
|
+
'transaction_code' => '171',
|
114
|
+
'primanota' => '281',
|
115
|
+
'details' => '?00SEPA LASTSCHRIFT KUNDE?10281?20KREF+EREF+TRX-0A4A47C3-F846-4729?21-8A1B-5DF620F?22MREF+CAC97D2144174318AC18D9?23BF815BD4FB?24CRED+DE98ZZZ09999999999?25SVWZ+FOO TRX-0A4A47C3-F84?266-4729-8A1B-5DF620F?30HYVEDEMMXXX?31HUkkbbbsssskcccccccccccccccx?32Peter Pan?99?34171'
|
116
|
+
)
|
117
|
+
end
|
118
|
+
end
|
78
119
|
end
|
79
120
|
|
80
121
|
describe 'information parsing with empty fields on the end' do
|
data/spec/statement_spec.rb
CHANGED
@@ -214,6 +214,13 @@ describe Cmxl do
|
|
214
214
|
end
|
215
215
|
|
216
216
|
context "when strip_headers is disabled" do
|
217
|
+
around do |example|
|
218
|
+
existing_value = Cmxl.config[:strip_headers]
|
219
|
+
Cmxl.config[:strip_headers] = false
|
220
|
+
example.run
|
221
|
+
Cmxl.config[:strip_headers] = existing_value
|
222
|
+
end
|
223
|
+
|
217
224
|
it "raise an parsing error exception if headers are present" do
|
218
225
|
data = <<~MT940.chomp
|
219
226
|
{1:D02AASDISLNETAXXXXXXXXXXXXX}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmxl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bumann
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-04 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rchardet
|