mt940 0.5.1 → 0.6.3
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.
- data/CHANGELOG +15 -0
- data/README.md +2 -1
- data/VERSION +1 -1
- data/lib/mt940/banks/abnamro.rb +12 -0
- data/lib/mt940/banks/ing.rb +7 -0
- data/lib/mt940/banks/rabobank.rb +1 -1
- data/lib/mt940/banks/triodos.rb +7 -0
- data/lib/mt940/base.rb +12 -4
- data/mt940.gemspec +2 -2
- data/test/fixtures/abnamro.txt +1 -1
- data/test/fixtures/ing.txt +1 -1
- data/test/fixtures/rabobank.txt +2 -1
- data/test/fixtures/triodos.txt +1 -1
- data/test/test_mt940_abnamro.rb +17 -2
- data/test/test_mt940_ing.rb +9 -5
- data/test/test_mt940_rabobank.rb +13 -3
- data/test/test_mt940_triodos.rb +6 -2
- metadata +4 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
* 0.6.3
|
2
|
+
|
3
|
+
- include the updated Changelog and README as well
|
4
|
+
|
5
|
+
* 0.6.2 (Was never released)
|
6
|
+
|
7
|
+
- Parse a NONREF contra account for the rabobank correctly
|
8
|
+
|
9
|
+
* 0.6.1 (Was never released)
|
10
|
+
|
11
|
+
- Extracting contra account for ING, AbnAmro and Triodos as well
|
12
|
+
- Standardized all account numbers to exactly 9 digits
|
13
|
+
|
14
|
+
* 0.6.0 (Was never released)
|
15
|
+
|
1
16
|
* 0.5.1
|
2
17
|
|
3
18
|
- Delegated determination of bank to corresponding subclass
|
data/README.md
CHANGED
@@ -35,8 +35,9 @@ or with the file itself:
|
|
35
35
|
- date
|
36
36
|
- amount (which is negative in case of a withdrawal)
|
37
37
|
- description
|
38
|
+
- contra account
|
38
39
|
|
39
|
-
* With the Rabobank
|
40
|
+
* With the Rabobank its owner is extracted as well.
|
40
41
|
|
41
42
|
|
42
43
|
Contributing to MT940
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.3
|
data/lib/mt940/banks/abnamro.rb
CHANGED
@@ -14,4 +14,16 @@ class MT940::Abnamro < MT940::Base
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def parse_contra_account
|
18
|
+
if @transaction
|
19
|
+
if @transaction.description.match(/^(GIRO)\s+(\d+)(.+)/)
|
20
|
+
@transaction.contra_account = $2.rjust(9, '000000000')
|
21
|
+
@transaction.description = $3
|
22
|
+
elsif @transaction.description.match(/^(\d{2}.\d{2}.\d{2}.\d{3})(.+)/)
|
23
|
+
@transaction.description = $2
|
24
|
+
@transaction.contra_account = $1.gsub('.','')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
17
29
|
end
|
data/lib/mt940/banks/ing.rb
CHANGED
@@ -4,4 +4,11 @@ class MT940::Ing < MT940::Base
|
|
4
4
|
self if args[0].match(/INGBNL/)
|
5
5
|
end
|
6
6
|
|
7
|
+
def parse_contra_account
|
8
|
+
if @transaction && @transaction.description.match(/^\d(\d{9})(.+)/)
|
9
|
+
@transaction.contra_account = $1
|
10
|
+
@transaction.description = $2
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
7
14
|
end
|
data/lib/mt940/banks/rabobank.rb
CHANGED
@@ -5,7 +5,7 @@ class MT940::Rabobank < MT940::Base
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def parse_tag_61
|
8
|
-
if @line.match(/^:61:(\d{6})(C|D)(\d+),(\d{0,2})\w{4}(
|
8
|
+
if @line.match(/^:61:(\d{6})(C|D)(\d+),(\d{0,2})\w{4}\w{1}(\d{9}|NONREF)(.+)$/)
|
9
9
|
type = $2 == 'D' ? -1 : 1
|
10
10
|
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f, :bank => @bank)
|
11
11
|
@transaction.date = parse_date($1)
|
data/lib/mt940/banks/triodos.rb
CHANGED
@@ -4,4 +4,11 @@ class MT940::Triodos < MT940::Base
|
|
4
4
|
self if args[0].match(/^:20:/) && args[1] && args[1].match(/^:25:TRIODOSBANK/)
|
5
5
|
end
|
6
6
|
|
7
|
+
def parse_contra_account
|
8
|
+
if @transaction && @transaction.description.match(/\d+(\d{9})$/)
|
9
|
+
@transaction.contra_account = $1.rjust(9, '000000000')
|
10
|
+
@transaction.description = ''
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
7
14
|
end
|
data/lib/mt940/base.rb
CHANGED
@@ -31,7 +31,7 @@ module MT940
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def self.determine_bank(*args)
|
34
|
-
Dir.foreach('
|
34
|
+
Dir.foreach(File.dirname(__FILE__) + '/banks/') do |file|
|
35
35
|
if file.match(/\.rb$/)
|
36
36
|
klass = eval(file.gsub(/\.rb$/,'').capitalize)
|
37
37
|
bank = klass.determine_bank(*args)
|
@@ -51,7 +51,7 @@ module MT940
|
|
51
51
|
def parse_tag_25
|
52
52
|
@line.gsub!('.','')
|
53
53
|
if @line.match(/^:\d{2}:[^\d]*(\d*)/)
|
54
|
-
@bank_account = $1
|
54
|
+
@bank_account = $1.gsub(/^0/,'')
|
55
55
|
@tag86 = false
|
56
56
|
end
|
57
57
|
end
|
@@ -69,18 +69,26 @@ module MT940
|
|
69
69
|
def parse_tag_86
|
70
70
|
if !@tag86 && @line.match(/^:86:\s?(.*)$/)
|
71
71
|
@tag86 = true
|
72
|
-
@transaction.description = $1.gsub(/>\d{2}/,'')
|
72
|
+
@transaction.description = $1.gsub(/>\d{2}/,'').strip
|
73
|
+
parse_contra_account
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
77
|
def parse_line
|
77
|
-
@
|
78
|
+
if @tag86 && @transaction.description
|
79
|
+
@transaction.description.lstrip!
|
80
|
+
@transaction.description += ' ' + @line.gsub(/\n/,'').gsub(/>\d{2}\s*/,'').gsub(/\-XXX/,'').gsub(/-$/,'').strip
|
81
|
+
@transaction.description.strip!
|
82
|
+
end
|
78
83
|
end
|
79
84
|
|
80
85
|
def parse_date(string)
|
81
86
|
Date.new(2000 + string[0..1].to_i, string[2..3].to_i, string[4..5].to_i) if string
|
82
87
|
end
|
83
88
|
|
89
|
+
def parse_contra_account
|
90
|
+
end
|
91
|
+
|
84
92
|
#Fail silently
|
85
93
|
def method_missing(*args)
|
86
94
|
end
|
data/mt940.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mt940}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["dovadi"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-06}
|
13
13
|
s.description = %q{A basic MT940 parser with implementations for Dutch banks.}
|
14
14
|
s.email = %q{frank.oxener@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/fixtures/abnamro.txt
CHANGED
@@ -36,6 +36,6 @@ ABNANL2A
|
|
36
36
|
:61:1105240524D9,49N426NONREF
|
37
37
|
:86:BEA NR:XXX1234 24.05.11/09.18 PETS PLACE KATWIJK KATWI,PAS999
|
38
38
|
:61:1105240524D15,N426NONREF
|
39
|
-
:86:
|
39
|
+
:86:52.89.39.882 MYCOM DEN HAAG S-GRAVEN,PAS999
|
40
40
|
:62F:C110524EUR1849,75
|
41
41
|
-
|
data/test/fixtures/ing.txt
CHANGED
@@ -18,7 +18,7 @@ ING Bank N.V. tarifering ING
|
|
18
18
|
:61:100722D1,10NGT NONREF
|
19
19
|
:86:0111111111 GPPeking 170000001AC
|
20
20
|
:61:100722C3,68NVZ NONREF
|
21
|
-
:86:
|
21
|
+
:86:0123456789 EJ46GREENP100610T1456 CLIEOP TMG GPHONGKONG AMSTERDAM
|
22
22
|
:62F:C100723EUR3,47
|
23
23
|
:86:D000004C000002D25,24C28,71
|
24
24
|
-XXX
|
data/test/fixtures/rabobank.txt
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
:940:
|
2
|
-
|
3
2
|
:20:940A110615
|
4
3
|
:25:1291.99.348EUR
|
5
4
|
:28:00000/00
|
@@ -21,4 +20,6 @@
|
|
21
20
|
:61:110617D000000000044,95N0600733959555 T-MOBILE NETHERLANDS BV
|
22
21
|
:86:BETALINGSKENM. 123456789
|
23
22
|
:86:FACTUURNUMMER 987654321
|
23
|
+
:61:110721D000000000236,56N030NONREF TOMTE TUMMETOT AMERSFOORT
|
24
|
+
:86:Betaalautomaat 14:23 pasnr. 065
|
24
25
|
:62F:C110617EUR0000000001250,87
|
data/test/fixtures/triodos.txt
CHANGED
data/test/test_mt940_abnamro.rb
CHANGED
@@ -21,8 +21,14 @@ class TestMt940Abnamro < Test::Unit::TestCase
|
|
21
21
|
assert_equal -9.00, @transaction.amount
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
context 'Description' do
|
25
|
+
should 'have the correct description in case of a GIRO account' do
|
26
|
+
assert_equal 'KPN - DIGITENNE BETALINGSKENM. 000000042188659 5314606715 BETREFT FACTUUR D.D. 20-05-2011 INCL. 1,44 BTW', @transaction.description
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'have the correct description in case of a regular bank' do
|
30
|
+
assert_equal 'MYCOM DEN HAAG S-GRAVEN,PAS999 :62F:C110524EUR1849,75', @transactions.last.description
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
34
|
should 'have a date' do
|
@@ -33,6 +39,15 @@ class TestMt940Abnamro < Test::Unit::TestCase
|
|
33
39
|
assert_equal 'Abnamro', @transaction.bank
|
34
40
|
end
|
35
41
|
|
42
|
+
context 'Contra account' do
|
43
|
+
should 'be determined in case of a GIRO account' do
|
44
|
+
assert_equal '000428428', @transaction.contra_account
|
45
|
+
end
|
46
|
+
|
47
|
+
should 'be determined in case of a regular bank' do
|
48
|
+
assert_equal '528939882', @transactions.last.contra_account
|
49
|
+
end
|
50
|
+
end
|
36
51
|
end
|
37
52
|
|
38
53
|
end
|
data/test/test_mt940_ing.rb
CHANGED
@@ -14,17 +14,13 @@ class TestMt940Ing < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
context 'Transaction' do
|
16
16
|
should 'have a bank_account' do
|
17
|
-
assert_equal '
|
17
|
+
assert_equal '001234567', @transaction.bank_account
|
18
18
|
end
|
19
19
|
|
20
20
|
should 'have an amount' do
|
21
21
|
assert_equal -25.03, @transaction.amount
|
22
22
|
end
|
23
23
|
|
24
|
-
should 'have a description' do
|
25
|
-
assert_equal 'RC AFREKENING BETALINGSVERKEER BETREFT REKENING 4715589 PERIODE: 01-10-2010 / 31-12-2010 ING Bank N.V. tarifering ING', @transaction.description
|
26
|
-
end
|
27
|
-
|
28
24
|
should 'have a date' do
|
29
25
|
assert_equal Date.new(2010,7,22), @transaction.date
|
30
26
|
end
|
@@ -33,6 +29,14 @@ class TestMt940Ing < Test::Unit::TestCase
|
|
33
29
|
assert_equal 'Ing', @transaction.bank
|
34
30
|
end
|
35
31
|
|
32
|
+
should 'have a description' do
|
33
|
+
assert_equal 'EJ46GREENP100610T1456 CLIEOP TMG GPHONGKONG AMSTERDAM :62F:C100723EUR3,47', @transactions.last.description
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'return the contra_account' do
|
37
|
+
assert_equal '123456789', @transactions.last.contra_account
|
38
|
+
end
|
39
|
+
|
36
40
|
end
|
37
41
|
|
38
42
|
end
|
data/test/test_mt940_rabobank.rb
CHANGED
@@ -9,7 +9,7 @@ class TestMt940Rabobank < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
should 'have the correct number of transactions' do
|
12
|
-
assert_equal
|
12
|
+
assert_equal 3, @transactions.size
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'Transaction' do
|
@@ -17,8 +17,18 @@ class TestMt940Rabobank < Test::Unit::TestCase
|
|
17
17
|
assert_equal '129199348', @transaction.bank_account
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
context 'Contra account' do
|
21
|
+
should 'be determined in case of a GIRO account' do
|
22
|
+
assert_equal '005675159', @transaction.contra_account
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'be determined in case of a regular bank' do
|
26
|
+
assert_equal '733959555', @transactions[1].contra_account
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'be determined in case of a NONREF' do
|
30
|
+
assert_equal 'NONREF', @transactions.last.contra_account
|
31
|
+
end
|
22
32
|
end
|
23
33
|
|
24
34
|
should 'have an amount' do
|
data/test/test_mt940_triodos.rb
CHANGED
@@ -14,7 +14,7 @@ class TestMt940Triodos < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
context 'Transaction' do
|
16
16
|
should 'have a bank_account' do
|
17
|
-
assert_equal '
|
17
|
+
assert_equal '390123456', @transaction.bank_account
|
18
18
|
end
|
19
19
|
|
20
20
|
should 'have an amount' do
|
@@ -22,7 +22,7 @@ class TestMt940Triodos < Test::Unit::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
should 'have a description' do
|
25
|
-
assert_equal '
|
25
|
+
assert_equal 'ALGEMENE TUSSENREKENING KOSTEN VAN 01-10-2010 TOT EN M ET 31-12-20100390123456', @transaction.description
|
26
26
|
end
|
27
27
|
|
28
28
|
should 'have a date' do
|
@@ -33,6 +33,10 @@ class TestMt940Triodos < Test::Unit::TestCase
|
|
33
33
|
assert_equal 'Triodos', @transaction.bank
|
34
34
|
end
|
35
35
|
|
36
|
+
should 'return the contra_account' do
|
37
|
+
assert_equal '987654321', @transaction.contra_account
|
38
|
+
end
|
39
|
+
|
36
40
|
end
|
37
41
|
|
38
42
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 6
|
8
|
+
- 3
|
9
|
+
version: 0.6.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- dovadi
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-07-
|
17
|
+
date: 2011-07-06 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|