mt940 0.1.0 → 0.2.0
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 +8 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +1 -0
- data/README.md +2 -3
- data/VERSION +1 -1
- data/lib/mt940/banks/abnamro.rb +6 -17
- data/lib/mt940/banks/ing.rb +0 -21
- data/lib/mt940/banks/rabobank.rb +12 -14
- data/lib/mt940/banks/triodos.rb +0 -21
- data/lib/mt940/base.rb +50 -3
- data/mt940.gemspec +71 -0
- data/test/test_mt940_abnamro.rb +1 -1
- data/test/test_mt940_ing.rb +1 -1
- data/test/test_mt940_rabobank.rb +2 -2
- data/test/test_mt940_triodos.rb +2 -2
- metadata +5 -4
- data/test/test_mt940.rb +0 -13
data/CHANGELOG
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -13,10 +13,9 @@ The following Dutch banks are implemented:
|
|
13
13
|
Usage
|
14
14
|
=====
|
15
15
|
|
16
|
-
* At this moment there is no automatic determination which bank needs to be parsed. So you need to choose the corresponding MT940 subclass for the specific bank you want to parse.
|
17
|
-
|
18
16
|
`file_name = File.dirname(__FILE__) + 'ing.940'`
|
19
|
-
|
17
|
+
|
18
|
+
`@transactions = MT940:::Base.transactions(file_name)`
|
20
19
|
|
21
20
|
* Independent of the bank, a transaction always consists of an amount and a description.
|
22
21
|
* With some implementations the contra_account with its owner is extracted as well.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/mt940/banks/abnamro.rb
CHANGED
@@ -1,22 +1,11 @@
|
|
1
1
|
class MT940::Abnamro < MT940::Base
|
2
2
|
|
3
|
-
def
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
elsif line.match(/^:61:\d{6}\d{4}(C|D)(\d+),(\d{0,2})/) #:61:1105240524D9,N192NONREF
|
10
|
-
type = $1 == 'D' ? -1 : 1
|
11
|
-
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($2 + '.' + $3).to_f)
|
12
|
-
@transactions << @transaction
|
13
|
-
tag86 = false
|
14
|
-
elsif line.match(/^:86:(.*)$/)
|
15
|
-
@transaction.description = $1.strip
|
16
|
-
tag86 = true
|
17
|
-
elsif tag86 && line.match(/^[^:]/)
|
18
|
-
@transaction.description += ' ' + line.strip.gsub(/\n/,'')
|
19
|
-
end
|
3
|
+
def parse_tag_61
|
4
|
+
if @line.match(/^:61:\d{6}\d{4}(C|D)(\d+),(\d{0,2})/)
|
5
|
+
type = $1 == 'D' ? -1 : 1
|
6
|
+
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($2 + '.' + $3).to_f)
|
7
|
+
@transactions << @transaction
|
8
|
+
@tag86 = false
|
20
9
|
end
|
21
10
|
end
|
22
11
|
|
data/lib/mt940/banks/ing.rb
CHANGED
@@ -1,23 +1,2 @@
|
|
1
1
|
class MT940::ING < MT940::Base
|
2
|
-
|
3
|
-
def parse
|
4
|
-
tag86 = false
|
5
|
-
@lines.each do |line|
|
6
|
-
if line.match(/^:25:(\d{10})/)
|
7
|
-
@bank_account = $1
|
8
|
-
tag86 = false
|
9
|
-
elsif line.match(/^:61:(\d{6})(C|D)(\d+),(\d{0,2})/)
|
10
|
-
type = $2 == 'D' ? -1 : 1
|
11
|
-
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f)
|
12
|
-
@transactions << @transaction
|
13
|
-
tag86 = false
|
14
|
-
elsif line.match(/^:86:\s?(.*)$/)
|
15
|
-
tag86 = true
|
16
|
-
@transaction.description = $1
|
17
|
-
elsif tag86 && line.match(/^[^:]/)
|
18
|
-
@transaction.description += ' ' + line.strip.gsub(/\n/,'')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
2
|
end
|
data/lib/mt940/banks/rabobank.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
class MT940::Rabobank < MT940::Base
|
2
2
|
|
3
|
-
def
|
4
|
-
@
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@transaction.contra_account = $4.strip
|
11
|
-
@transaction.contra_account_name = $5.strip
|
12
|
-
@transactions << @transaction
|
13
|
-
elsif line.match(/^:86:(.*)$/)
|
14
|
-
@transaction.description = $1.strip
|
15
|
-
end
|
3
|
+
def parse_tag_61
|
4
|
+
if @line.match(/^:61:\d{6}(C|D)(\d+),(\d{0,2})\w{4}(.{16})(.+)$/)
|
5
|
+
type = $1 == 'D' ? -1 : 1
|
6
|
+
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($2 + '.' + $3).to_f)
|
7
|
+
@transaction.contra_account = $4.strip
|
8
|
+
@transaction.contra_account_name = $5.strip
|
9
|
+
@transactions << @transaction
|
16
10
|
end
|
17
11
|
end
|
18
12
|
|
19
|
-
|
13
|
+
def parse_tag_86
|
14
|
+
@transaction.description = $1.strip if @line.match(/^:86:(.*)$/)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/mt940/banks/triodos.rb
CHANGED
@@ -1,23 +1,2 @@
|
|
1
1
|
class MT940::Triodos < MT940::Base
|
2
|
-
|
3
|
-
def parse
|
4
|
-
tag86 = false
|
5
|
-
@lines.each do |line|
|
6
|
-
if line.match(/^:25:TRIODOSBANK\/(\d*)$/)
|
7
|
-
@bank_account = $1
|
8
|
-
tag86 = false
|
9
|
-
elsif line.match(/^:61:\d{6}(C|D)(\d+),(\d{0,2})/) #:61:1105240524D9,N192NONREF
|
10
|
-
type = $1 == 'D' ? -1 : 1
|
11
|
-
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($2 + '.' + $3).to_f)
|
12
|
-
@transactions << @transaction
|
13
|
-
tag86 = false
|
14
|
-
elsif line.match(/^:86:(.*)$/)
|
15
|
-
@transaction.description = $1.strip.gsub(/>\d{2}/,'')
|
16
|
-
tag86 = true
|
17
|
-
elsif tag86 && line.match(/^[^:]/)
|
18
|
-
@transaction.description += line.strip.gsub(/\n/,'').gsub(/>\d{2}/,'')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
2
|
end
|
data/lib/mt940/base.rb
CHANGED
@@ -3,11 +3,30 @@ module MT940
|
|
3
3
|
class Base
|
4
4
|
|
5
5
|
def self.transactions(file_name)
|
6
|
-
|
6
|
+
first_line = File.open(file_name) {|f| f.readline}
|
7
|
+
klass = if first_line.match(/INGBNL/)
|
8
|
+
ING
|
9
|
+
elsif first_line.match(/ABNANL/)
|
10
|
+
Abnamro
|
11
|
+
elsif first_line.match(/^:940:/)
|
12
|
+
Rabobank
|
13
|
+
else
|
14
|
+
self
|
15
|
+
end
|
16
|
+
instance = klass.new(file_name)
|
7
17
|
instance.parse
|
8
18
|
instance.instance_variable_get('@transactions')
|
9
19
|
end
|
10
20
|
|
21
|
+
def parse
|
22
|
+
@tag86 = false
|
23
|
+
@lines.each do |line|
|
24
|
+
@line = line
|
25
|
+
@line.match(/^:(\d{2}):/) ? eval('parse_tag_'+ $1) : parse_line
|
26
|
+
end
|
27
|
+
@transactions
|
28
|
+
end
|
29
|
+
|
11
30
|
private
|
12
31
|
|
13
32
|
def initialize(file_name)
|
@@ -15,8 +34,36 @@ module MT940
|
|
15
34
|
@lines = File.readlines(file_name)
|
16
35
|
end
|
17
36
|
|
18
|
-
def
|
19
|
-
|
37
|
+
def parse_tag_25
|
38
|
+
@line.gsub!('.','')
|
39
|
+
if @line.match(/^:\d{2}:[^\d]*(\d*)/)
|
40
|
+
@bank_account = $1
|
41
|
+
@tag86 = false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse_tag_61
|
46
|
+
if @line.match(/^:61:(\d{6})(C|D)(\d+),(\d{0,2})/)
|
47
|
+
type = $2 == 'D' ? -1 : 1
|
48
|
+
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f)
|
49
|
+
@transactions << @transaction
|
50
|
+
@tag86 = false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_tag_86
|
55
|
+
if !@tag86 && @line.match(/^:86:\s?(.*)$/)
|
56
|
+
@tag86 = true
|
57
|
+
@transaction.description = $1.gsub(/>\d{2}/,'')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_line
|
62
|
+
@transaction.description += ' ' + @line.gsub(/\n/,'').gsub(/>\d{2}/,'') if @tag86
|
63
|
+
end
|
64
|
+
|
65
|
+
#Fail silently
|
66
|
+
def method_missing(*args)
|
20
67
|
end
|
21
68
|
|
22
69
|
end
|
data/mt940.gemspec
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mt940}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["dovadi"]
|
12
|
+
s.date = %q{2011-06-24}
|
13
|
+
s.description = %q{A basic MT940 parser with implementations for Dutch banks.}
|
14
|
+
s.email = %q{frank.oxener@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"CHANGELOG",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/mt940.rb",
|
29
|
+
"lib/mt940/banks/abnamro.rb",
|
30
|
+
"lib/mt940/banks/ing.rb",
|
31
|
+
"lib/mt940/banks/rabobank.rb",
|
32
|
+
"lib/mt940/banks/triodos.rb",
|
33
|
+
"lib/mt940/base.rb",
|
34
|
+
"lib/mt940/transaction.rb",
|
35
|
+
"mt940.gemspec",
|
36
|
+
"test/fixtures/abnamro.txt",
|
37
|
+
"test/fixtures/ing.txt",
|
38
|
+
"test/fixtures/rabobank.txt",
|
39
|
+
"test/fixtures/triodos.txt",
|
40
|
+
"test/helper.rb",
|
41
|
+
"test/test_mt940_abnamro.rb",
|
42
|
+
"test/test_mt940_ing.rb",
|
43
|
+
"test/test_mt940_rabobank.rb",
|
44
|
+
"test/test_mt940_triodos.rb"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://github.com/dovadi/mt940}
|
47
|
+
s.licenses = ["MIT"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.6}
|
50
|
+
s.summary = %q{MT940 parser}
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/test/test_mt940_abnamro.rb
CHANGED
@@ -4,7 +4,7 @@ class TestMt940Abnamro < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
file_name = File.dirname(__FILE__) + '/fixtures/abnamro.txt'
|
7
|
-
@transactions = MT940::
|
7
|
+
@transactions = MT940::Base.transactions(file_name)
|
8
8
|
@transaction = @transactions.first
|
9
9
|
end
|
10
10
|
|
data/test/test_mt940_ing.rb
CHANGED
@@ -4,7 +4,7 @@ class TestMt940Ing < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
file_name = File.dirname(__FILE__) + '/fixtures/ing.txt'
|
7
|
-
@transactions = MT940::
|
7
|
+
@transactions = MT940::Base.transactions(file_name)
|
8
8
|
@transaction = @transactions.first
|
9
9
|
end
|
10
10
|
|
data/test/test_mt940_rabobank.rb
CHANGED
@@ -4,7 +4,7 @@ class TestMt940Rabobank < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
file_name = File.dirname(__FILE__) + '/fixtures/rabobank.txt'
|
7
|
-
@transactions = MT940::
|
7
|
+
@transactions = MT940::Base.transactions(file_name)
|
8
8
|
@transaction = @transactions.first
|
9
9
|
end
|
10
10
|
|
@@ -14,7 +14,7 @@ class TestMt940Rabobank < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
context 'Transaction' do
|
16
16
|
should 'have a bank_account' do
|
17
|
-
assert_equal '
|
17
|
+
assert_equal '129199348', @transaction.bank_account
|
18
18
|
end
|
19
19
|
|
20
20
|
should 'have a contra_account' do
|
data/test/test_mt940_triodos.rb
CHANGED
@@ -4,7 +4,7 @@ class TestMt940Triodos < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
file_name = File.dirname(__FILE__) + '/fixtures/triodos.txt'
|
7
|
-
@transactions = MT940::
|
7
|
+
@transactions = MT940::Base.transactions(file_name)
|
8
8
|
@transaction = @transactions.first
|
9
9
|
end
|
10
10
|
|
@@ -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 '0000000000000 ALGEMENE TUSSENREKENING KOSTEN VAN 01-10-2010 TOT EN M ET 31-12-20100390123456', @transaction.description
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
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-06-
|
17
|
+
date: 2011-06-24 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -68,6 +68,7 @@ extra_rdoc_files:
|
|
68
68
|
- README.md
|
69
69
|
files:
|
70
70
|
- .document
|
71
|
+
- CHANGELOG
|
71
72
|
- Gemfile
|
72
73
|
- Gemfile.lock
|
73
74
|
- LICENSE.txt
|
@@ -81,12 +82,12 @@ files:
|
|
81
82
|
- lib/mt940/banks/triodos.rb
|
82
83
|
- lib/mt940/base.rb
|
83
84
|
- lib/mt940/transaction.rb
|
85
|
+
- mt940.gemspec
|
84
86
|
- test/fixtures/abnamro.txt
|
85
87
|
- test/fixtures/ing.txt
|
86
88
|
- test/fixtures/rabobank.txt
|
87
89
|
- test/fixtures/triodos.txt
|
88
90
|
- test/helper.rb
|
89
|
-
- test/test_mt940.rb
|
90
91
|
- test/test_mt940_abnamro.rb
|
91
92
|
- test/test_mt940_ing.rb
|
92
93
|
- test/test_mt940_rabobank.rb
|
data/test/test_mt940.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestMt940 < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@file_name = File.dirname(__FILE__) + '/fixtures/ing.txt'
|
7
|
-
end
|
8
|
-
|
9
|
-
should 'raise a NoMethodError if not implemented' do
|
10
|
-
assert_raise(NoMethodError) { MT940::Base.get_transactions(@file_name) }
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|