cmxl 1.4.6 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/CHANGELOG.mdown +8 -0
- data/README.md +13 -13
- data/lib/cmxl.rb +2 -2
- data/lib/cmxl/fields/transaction.rb +1 -1
- data/lib/cmxl/statement.rb +2 -1
- data/lib/cmxl/version.rb +1 -1
- data/spec/fields/transaction_spec.rb +16 -0
- data/spec/fixtures/lines/statement_line.txt +2 -0
- data/spec/fixtures/mt940.txt +31 -0
- data/spec/fixtures/mt942.txt +12 -0
- data/spec/mt940_parsing_spec.rb +8 -1
- data/spec/statement_spec.rb +16 -0
- metadata +4 -4
- data/.semaphore/semaphore.yml +0 -101
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 661a3296bdc88ce9874f07cb4a1cf4220bf1a60ea559e289edc5c5c34774764b
|
4
|
+
data.tar.gz: 4f0217f656646bd14540e5993f6419354641f30d901e8b7afc884b46fc5ac69e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 407ecb157601f8cc767ddb7699edbadc66582041cdcd8d1de3b3e169a41865d3f81ffdb794b7b9f8add8a55ecea1e16e4048f30a117cfe2401b05b487d2e1bcf
|
7
|
+
data.tar.gz: 4cbfe3e46cc9a00527bfa1a4d465f5e0ad4311d915449b45a81b172e1a653ee3ec2605778bb1241aca752016651b8f54dad0daf00769349a6a80cb679cff0dcf
|
data/.travis.yml
ADDED
data/CHANGELOG.mdown
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# NEXT release
|
2
|
+
|
3
|
+
# 1.5.0
|
4
|
+
|
5
|
+
- `[BUGFIX]` fix potential bug when generation_date is not provided in field 20 and 13 (issue: [#35](https://github.com/railslove/cmxl/issues/35) PR: [#36](https://github.com/railslove/cmxl/pull/36))
|
6
|
+
- `[FEATURE]` add transaction type 'S' to Field 61 (swift_code) (issue: [#38](https://github.com/railslove/cmxl/issues/38) PR: [#42](https://github.com/railslove/cmxl/pull/42)
|
7
|
+
- `[ENHANCEMENT]` [Fix deprecations in ruby 2.7 for kw params](https://github.com/railslove/cmxl/commit/905cd50e5372da312a653c89e77727a14751b5ec)
|
8
|
+
|
1
9
|
# 1.4.6
|
2
10
|
|
3
11
|
- `[ENHANCEMENT]` make sure that tag, gemversion and readme align ʘ‿ʘ
|
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
[![Build Status](https://
|
2
|
-
[![Code Climate](https://codeclimate.com/github/railslove/cmxl/badges/gpa.svg)](https://codeclimate.com/github/railslove/cmxl)
|
3
|
-
[![Test Coverage](https://codeclimate.com/github/railslove/cmxl/badges/coverage.svg)](https://codeclimate.com/github/railslove/cmxl)
|
1
|
+
[![Build Status](https://travis-ci.org/railslove/cmxl.svg?branch=master)](https://travis-ci.org/railslove/cmxl)
|
4
2
|
[![Gem Version](https://badge.fury.io/rb/cmxl.svg)](http://badge.fury.io/rb/cmxl)
|
5
3
|
|
6
4
|
# Cmxl - your friendly ruby MT940 parser
|
@@ -8,7 +6,7 @@
|
|
8
6
|
At [Railslove](http://railslove.com) we build a lot of financial applications and work on integrating applications with banks and banking functionality.
|
9
7
|
Our goal is to make simple solutions for what often looks complicated.
|
10
8
|
|
11
|
-
Cmxl is a friendly and
|
9
|
+
Cmxl is a friendly and extensible MT940 bank statement file parser that helps you extract data from bank statement files.
|
12
10
|
|
13
11
|
## What is MT940 & MT942?
|
14
12
|
|
@@ -16,13 +14,13 @@ MT940 (MT = Message Type) is the SWIFT-Standard for the electronic transfer of b
|
|
16
14
|
When integrating with banks you often get MT940 or MT942 files as interface.
|
17
15
|
For more information have a look at the different [SWIFT message types](http://en.wikipedia.org/wiki/SWIFT_message_types)
|
18
16
|
|
19
|
-
At some point in the future MT940 file should be exchanged with newer XML documents - but banking institutions are slow so MT940 will stick around for a while.
|
17
|
+
At some point in the future MT940 file should be exchanged with newer XML documents - but banking institutions are slow, so MT940 will stick around for a while.
|
20
18
|
|
21
19
|
## Reqirements
|
22
20
|
|
23
21
|
Cmxl is a pure ruby parser and has no dependency on native extensions.
|
24
22
|
|
25
|
-
- Ruby
|
23
|
+
- Ruby (current officially supported distributions)
|
26
24
|
|
27
25
|
## Installation
|
28
26
|
|
@@ -52,7 +50,7 @@ Cmxl.config[:statement_separator] = /\n-.\n/m
|
|
52
50
|
# do you want an error to be raised when a line can not be parsed? default is true
|
53
51
|
Cmxl.config[:raise_line_format_errors] = true
|
54
52
|
|
55
|
-
# try to stip the SWIFT header data. This strips everything until the actual first MT940 field. (if parsing fails try this!)
|
53
|
+
# try to stip the SWIFT header data. This strips everything until the actual first MT940 field. (if parsing fails, try this!)
|
56
54
|
Cmxl.config[:strip_headers] = true
|
57
55
|
|
58
56
|
|
@@ -86,14 +84,14 @@ end
|
|
86
84
|
|
87
85
|
```
|
88
86
|
|
89
|
-
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
|
87
|
+
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.
|
90
88
|
|
91
|
-
#### A note about encoding and file
|
89
|
+
#### A note about encoding and file weirdnesses
|
92
90
|
|
93
91
|
You probably will encounter encoding issues (hey, you are building banking applications!).
|
94
|
-
We try to handle encoding and format
|
95
|
-
In the likely case that you
|
96
|
-
If that fails try to
|
92
|
+
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
|
+
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
|
+
If that fails, try to modify the file before you pass it to the parser - and please create an issue.
|
97
95
|
|
98
96
|
### MT940 SWIFT header data
|
99
97
|
|
@@ -188,5 +186,7 @@ other parsers:
|
|
188
186
|
- [gmitrev/mt940parser](https://github.com/gmitrev/mt940parser)
|
189
187
|
|
190
188
|
---
|
189
|
+
built with love by [Railslove](http://railslove.com) and some [amazing people](https://github.com/railslove/cmxl/graphs/contributors).
|
190
|
+
Released under the MIT-Licence.
|
191
191
|
|
192
|
-
|
192
|
+
Railslove builds FinTech products, if you need support for your project we are happy to help. Please contact us at team@railslove.com.
|
data/lib/cmxl.rb
CHANGED
@@ -36,9 +36,9 @@ module Cmxl
|
|
36
36
|
end
|
37
37
|
|
38
38
|
if options[:encoding]
|
39
|
-
data.encode!('UTF-8', options.delete(:encoding), options)
|
39
|
+
data.encode!('UTF-8', options.delete(:encoding), **options)
|
40
40
|
else
|
41
|
-
data.encode!('UTF-8', options) unless options.empty?
|
41
|
+
data.encode!('UTF-8', **options) unless options.empty?
|
42
42
|
end
|
43
43
|
|
44
44
|
data.split(options[:statement_separator]).reject { |s| s.strip.empty? }.collect { |s| Cmxl::Statement.new(s.strip) }
|
@@ -2,7 +2,7 @@ module Cmxl
|
|
2
2
|
module Fields
|
3
3
|
class Transaction < Field
|
4
4
|
self.tag = 61
|
5
|
-
self.parser = %r{^(?<date>\d{6})(?<entry_date>\d{4})?(?<storno_flag>R?)(?<funds_code>[CD]{1})(?<currency_letter>[a-zA-Z])?(?<amount>\d{1,12},\d{0,2})(?<swift_code>(?:N|F).{3})(?<reference>NONREF|(.(?!\/\/)){,16}([^\/]){,1})((?:\/\/)(?<bank_reference>[^\n]{,16}))?((?:\n)(?<supplementary>.{,34}))?$}
|
5
|
+
self.parser = %r{^(?<date>\d{6})(?<entry_date>\d{4})?(?<storno_flag>R?)(?<funds_code>[CD]{1})(?<currency_letter>[a-zA-Z])?(?<amount>\d{1,12},\d{0,2})(?<swift_code>(?:N|F|S).{3})(?<reference>NONREF|(.(?!\/\/)){,16}([^\/]){,1})((?:\/\/)(?<bank_reference>[^\n]{,16}))?((?:\n)(?<supplementary>.{,34}))?$}
|
6
6
|
|
7
7
|
attr_accessor :details
|
8
8
|
|
data/lib/cmxl/statement.rb
CHANGED
@@ -58,8 +58,9 @@ module Cmxl
|
|
58
58
|
field(20).reference
|
59
59
|
end
|
60
60
|
|
61
|
+
#Get generation date from field 20. If generation date is not provided in field 20, method will fall back to field 13 if present.
|
61
62
|
def generation_date
|
62
|
-
field(20).date || field(13).date
|
63
|
+
field(20).date || (field(13).nil? ? nil : field(13).date)
|
63
64
|
end
|
64
65
|
|
65
66
|
def account_identification
|
data/lib/cmxl/version.rb
CHANGED
@@ -9,6 +9,7 @@ describe Cmxl::Fields::Transaction do
|
|
9
9
|
subject(:complex_supplementary_transaction) { Cmxl::Fields::Transaction.parse(fixture_line(:statement_supplementary_complex)) }
|
10
10
|
subject(:valuta_after_enty_date) { Cmxl::Fields::Transaction.parse(fixture[3]) }
|
11
11
|
subject(:entry_before_valuta_transaction) { Cmxl::Fields::Transaction.parse(fixture[2]) }
|
12
|
+
subject(:transaction_type_swift) { Cmxl::Fields::Transaction.parse(fixture[4]) }
|
12
13
|
|
13
14
|
let(:fixture) { fixture_line(:statement_line).split(/\n/) }
|
14
15
|
|
@@ -91,4 +92,19 @@ describe Cmxl::Fields::Transaction do
|
|
91
92
|
expect(valuta_after_enty_date.entry_date).to eql(Date.new(2015, 1, 2))
|
92
93
|
end
|
93
94
|
end
|
95
|
+
|
96
|
+
context 'transaction type swift transfer' do
|
97
|
+
it { expect(transaction_type_swift.date).to eql(Date.new(2019, 11, 18)) }
|
98
|
+
it { expect(transaction_type_swift.entry_date).to eql(Date.new(2019, 11, 18)) }
|
99
|
+
it { expect(transaction_type_swift.funds_code).to eql('C') }
|
100
|
+
it { expect(transaction_type_swift.currency_letter).to eql('R') }
|
101
|
+
it { expect(transaction_type_swift.amount).to eql(653.0) }
|
102
|
+
it { expect(transaction_type_swift.amount_in_cents).to eql(65300) }
|
103
|
+
it { expect(transaction_type_swift.swift_code).to eql('S445') }
|
104
|
+
it { expect(transaction_type_swift.reference).to eql('328556-76501096') }
|
105
|
+
it { expect(transaction_type_swift).to be_credit }
|
106
|
+
it { expect(transaction_type_swift).not_to be_debit }
|
107
|
+
it { expect(transaction_type_swift).not_to be_storno }
|
108
|
+
it { expect(transaction_type_swift.sign).to eql(1) }
|
109
|
+
end
|
94
110
|
end
|
data/spec/fixtures/mt940.txt
CHANGED
@@ -74,3 +74,34 @@ Interest credit
|
|
74
74
|
:62F:C020325PLN50040,00
|
75
75
|
|
76
76
|
-
|
77
|
+
|
78
|
+
:20:01ANWZTPJTYEGJWA
|
79
|
+
:25:45050050/76198810
|
80
|
+
:28:27/01
|
81
|
+
:60F:C131016DEM84349,74
|
82
|
+
:61:131017D6800,NCHK16703074
|
83
|
+
:86:999PN5477SCHECK-NR. 0000016703074
|
84
|
+
:61:131017D620,3NSTON
|
85
|
+
:86:999PN0911DAUERAUFTR.NR. 14
|
86
|
+
:61:131017C18500,NCLRN
|
87
|
+
:86:999PN2406SCHECK
|
88
|
+
:61:131015D14220,NBOEN
|
89
|
+
:86:999PN0920WECHSEL
|
90
|
+
:61:131017D1507,NTRFN
|
91
|
+
:86:999PN0920SCHNELLUEB
|
92
|
+
:61:131024C4200,NMSCN
|
93
|
+
:86:999PN2506AUSSENH. NR. 1
|
94
|
+
:61:131017D19900,NTRFN
|
95
|
+
:86:999PN0907UEBERTRAG
|
96
|
+
:61:131017D400,NTRFN
|
97
|
+
:86:999PN0891BTX
|
98
|
+
:61:131018C3656,74NMSCN
|
99
|
+
:86:999PN0850EINZAHLG.N
|
100
|
+
:61:131019C23040,NMSCN
|
101
|
+
:86:999PN0812LT.ANLAGE
|
102
|
+
:61:131027D5862,14NCHKN
|
103
|
+
:86:999PN5329AUSLSCHECK
|
104
|
+
:62F:C131017DEM84437,04
|
105
|
+
|
106
|
+
-
|
107
|
+
|
data/spec/fixtures/mt942.txt
CHANGED
@@ -7,3 +7,15 @@
|
|
7
7
|
:86:008?00DAUERAUFTRAG?100599?20Miete Dezember?3010020030?31234567?32MUELLER?34339
|
8
8
|
:90D:0EUR0,00
|
9
9
|
:90C:1EUR9792,00
|
10
|
+
|
11
|
+
-
|
12
|
+
|
13
|
+
:20:01ANWZTPJTYEGJWA
|
14
|
+
:25:45050050/76198810
|
15
|
+
:28C:13/37
|
16
|
+
:34F:EURD12345,67
|
17
|
+
:13D:1901091733+0100
|
18
|
+
:61:190109C9792,00FTRFNONREF
|
19
|
+
:86:008?00DAUERAUFTRAG?100599?20Miete Dezember?3010020030?31234567?32MUELLER?34339
|
20
|
+
:90D:0EUR0,00
|
21
|
+
:90C:1EUR9792,00
|
data/spec/mt940_parsing_spec.rb
CHANGED
@@ -61,11 +61,18 @@ describe 'parsing a statement' do
|
|
61
61
|
it { expect(subject.field('NS').to_h).to eql({tag: 'NS', modifier: 'F', source: 'HelloWorld'}) }
|
62
62
|
end
|
63
63
|
|
64
|
+
context 'no generation date' do
|
65
|
+
subject { Cmxl.parse(mt940_file('mt940'))[3] }
|
66
|
+
|
67
|
+
it { expect(subject.reference).to eql('01ANWZTPJTYEGJWA') }
|
68
|
+
it { expect(subject.generation_date).to eql(nil) }
|
69
|
+
end
|
70
|
+
|
64
71
|
context 'statement separator as used by most banks' do
|
65
72
|
subject { Cmxl.parse(mt940_file('mt940')) }
|
66
73
|
|
67
74
|
it 'detects all statements by default' do
|
68
|
-
expect(subject.size).to eq(
|
75
|
+
expect(subject.size).to eq(4)
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
data/spec/statement_spec.rb
CHANGED
@@ -145,4 +145,20 @@ describe Cmxl do
|
|
145
145
|
expect(subject.transactions.first.iban).to eq('234567')
|
146
146
|
end
|
147
147
|
end
|
148
|
+
|
149
|
+
context 'mt942 generation date from field 20' do
|
150
|
+
subject(:statement) { Cmxl.parse(mt940_file('mt942')).first }
|
151
|
+
|
152
|
+
it { expect(statement.mt942?).to be_truthy }
|
153
|
+
it { expect(statement.generation_date).to eql(Date.new(2013, 11, 10)) }
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'mt942 generation date from field 13' do
|
158
|
+
subject(:statement) { Cmxl.parse(mt940_file('mt942'))[1] }
|
159
|
+
|
160
|
+
it { expect(statement.mt942?).to be_truthy }
|
161
|
+
it { expect(statement.generation_date).to eql(Date.new(2019, 1, 9)) }
|
162
|
+
end
|
163
|
+
|
148
164
|
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.5.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:
|
11
|
+
date: 2020-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,7 +104,7 @@ extra_rdoc_files: []
|
|
104
104
|
files:
|
105
105
|
- ".gitignore"
|
106
106
|
- ".rspec"
|
107
|
-
- ".
|
107
|
+
- ".travis.yml"
|
108
108
|
- CHANGELOG.mdown
|
109
109
|
- Gemfile
|
110
110
|
- LICENSE.txt
|
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
198
|
- !ruby/object:Gem::Version
|
199
199
|
version: '0'
|
200
200
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
201
|
+
rubygems_version: 3.1.2
|
202
202
|
signing_key:
|
203
203
|
specification_version: 4
|
204
204
|
summary: Cmxl is your friendly MT940 bank statement parser
|
data/.semaphore/semaphore.yml
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
version: v1.0
|
2
|
-
name: Test
|
3
|
-
agent:
|
4
|
-
machine:
|
5
|
-
type: e1-standard-2
|
6
|
-
os_image: ubuntu1804
|
7
|
-
blocks:
|
8
|
-
- name: Setup
|
9
|
-
task:
|
10
|
-
jobs:
|
11
|
-
- name: Checkout
|
12
|
-
commands:
|
13
|
-
- checkout
|
14
|
-
- ls
|
15
|
-
- rm -f .rbenv-version .ruby-version
|
16
|
-
|
17
|
-
- name: Tests
|
18
|
-
task:
|
19
|
-
env_vars:
|
20
|
-
- name: CC_TEST_REPORTER_ID
|
21
|
-
value: 149f0d20e17ace00c44be432a4194bc441ba805da89a7708fca0f4a2c3f2aed7
|
22
|
-
jobs:
|
23
|
-
- name: "2.0.0-p648"
|
24
|
-
commands:
|
25
|
-
- checkout
|
26
|
-
- sem-version ruby 2.0.0-p648
|
27
|
-
- cache restore
|
28
|
-
- bundle install
|
29
|
-
- cache store
|
30
|
-
- bundle exec rspec
|
31
|
-
- name: "2.1.10"
|
32
|
-
commands:
|
33
|
-
- checkout
|
34
|
-
- sem-version ruby 2.1.10
|
35
|
-
- cache restore
|
36
|
-
- bundle install
|
37
|
-
- cache store
|
38
|
-
- bundle exec rspec
|
39
|
-
- name: "2.2.10"
|
40
|
-
commands:
|
41
|
-
- checkout
|
42
|
-
- sem-version ruby 2.2.10
|
43
|
-
- cache restore
|
44
|
-
- bundle install
|
45
|
-
- cache store
|
46
|
-
- bundle exec rspec
|
47
|
-
- name: "2.3"
|
48
|
-
commands:
|
49
|
-
- checkout
|
50
|
-
- sem-version ruby 2.3
|
51
|
-
- cache restore
|
52
|
-
- bundle install
|
53
|
-
- cache store
|
54
|
-
- bundle exec rspec
|
55
|
-
- name: "2.4"
|
56
|
-
commands:
|
57
|
-
- checkout
|
58
|
-
- sem-version ruby 2.4
|
59
|
-
- cache restore
|
60
|
-
- bundle install
|
61
|
-
- cache store
|
62
|
-
- bundle exec rspec
|
63
|
-
- name: "2.5"
|
64
|
-
commands:
|
65
|
-
- checkout
|
66
|
-
- sem-version ruby 2.5
|
67
|
-
- cache restore
|
68
|
-
- bundle install
|
69
|
-
- cache store
|
70
|
-
- bundle exec rspec
|
71
|
-
- name: "2.6 including Code Climate"
|
72
|
-
commands:
|
73
|
-
- checkout
|
74
|
-
- sem-version ruby 2.6
|
75
|
-
- cache restore
|
76
|
-
- bundle install
|
77
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
78
|
-
- chmod +x ./cc-test-reporter
|
79
|
-
- cache store
|
80
|
-
- ./cc-test-reporter before-build
|
81
|
-
- bundle exec rspec
|
82
|
-
- ./cc-test-reporter after-build
|
83
|
-
|
84
|
-
- name: "jruby-9.1.17.0"
|
85
|
-
commands:
|
86
|
-
- checkout
|
87
|
-
- sem-version ruby jruby-9.1.17.0
|
88
|
-
- cache restore
|
89
|
-
- gem install bundler
|
90
|
-
- bundle install
|
91
|
-
- cache store
|
92
|
-
- bundle exec rspec
|
93
|
-
- name: "jruby-9.2.0.0"
|
94
|
-
commands:
|
95
|
-
- checkout
|
96
|
-
- sem-version ruby jruby-9.2.0.0
|
97
|
-
- cache restore
|
98
|
-
- gem install bundler
|
99
|
-
- bundle install
|
100
|
-
- cache store
|
101
|
-
- bundle exec rspec
|