mt940 0.4.1 → 0.5.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/README.md +1 -0
- data/VERSION +1 -1
- data/lib/mt940/banks/abnamro.rb +1 -1
- data/lib/mt940/banks/ing.rb +1 -1
- data/lib/mt940/banks/rabobank.rb +1 -1
- data/lib/mt940/base.rb +14 -4
- data/lib/mt940/transaction.rb +2 -1
- data/mt940.gemspec +2 -1
- data/test/fixtures/unknown.txt +22 -0
- data/test/test_mt940_abnamro.rb +4 -0
- data/test/test_mt940_base.rb +38 -28
- data/test/test_mt940_ing.rb +5 -0
- data/test/test_mt940_rabobank.rb +4 -0
- data/test/test_mt940_triodos.rb +4 -0
- metadata +4 -3
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/mt940/banks/abnamro.rb
CHANGED
@@ -3,7 +3,7 @@ class MT940::Abnamro < MT940::Base
|
|
3
3
|
def parse_tag_61
|
4
4
|
if @line.match(/^:61:(\d{6})\d{4}(C|D)(\d+),(\d{0,2})/)
|
5
5
|
type = $2 == 'D' ? -1 : 1
|
6
|
-
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f)
|
6
|
+
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f, :bank => @bank)
|
7
7
|
@transaction.date = parse_date($1)
|
8
8
|
@transactions << @transaction
|
9
9
|
@tag86 = false
|
data/lib/mt940/banks/ing.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
class MT940::
|
1
|
+
class MT940::Ing < MT940::Base
|
2
2
|
end
|
data/lib/mt940/banks/rabobank.rb
CHANGED
@@ -3,7 +3,7 @@ class MT940::Rabobank < MT940::Base
|
|
3
3
|
def parse_tag_61
|
4
4
|
if @line.match(/^:61:(\d{6})(C|D)(\d+),(\d{0,2})\w{4}(.{16})(.+)$/)
|
5
5
|
type = $2 == 'D' ? -1 : 1
|
6
|
-
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f)
|
6
|
+
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f, :bank => @bank)
|
7
7
|
@transaction.date = parse_date($1)
|
8
8
|
@transaction.contra_account = $5.strip
|
9
9
|
@transaction.contra_account_owner = $6.strip
|
data/lib/mt940/base.rb
CHANGED
@@ -2,10 +2,16 @@ module MT940
|
|
2
2
|
|
3
3
|
class Base
|
4
4
|
|
5
|
+
attr_accessor :bank
|
6
|
+
|
5
7
|
def self.transactions(file)
|
6
8
|
file = File.open(file) if file.is_a?(String)
|
7
9
|
if file.is_a?(File) || file.is_a?(Tempfile)
|
8
|
-
|
10
|
+
first_line = file.readline
|
11
|
+
second_line = file.readline unless file.eof?
|
12
|
+
klass = determine_bank(first_line, second_line)
|
13
|
+
file.rewind
|
14
|
+
instance = klass.new(file)
|
9
15
|
file.close
|
10
16
|
instance.parse
|
11
17
|
else
|
@@ -24,13 +30,15 @@ module MT940
|
|
24
30
|
|
25
31
|
private
|
26
32
|
|
27
|
-
def self.determine_bank(first_line)
|
33
|
+
def self.determine_bank(first_line, second_line)
|
28
34
|
if first_line.match(/INGBNL/)
|
29
|
-
|
35
|
+
Ing
|
30
36
|
elsif first_line.match(/ABNANL/)
|
31
37
|
Abnamro
|
32
38
|
elsif first_line.match(/^:940:/)
|
33
39
|
Rabobank
|
40
|
+
elsif first_line.match(/^:20:/) && second_line && second_line.match(/^:25:TRIODOSBANK/)
|
41
|
+
Triodos
|
34
42
|
else
|
35
43
|
self
|
36
44
|
end
|
@@ -38,6 +46,8 @@ module MT940
|
|
38
46
|
|
39
47
|
def initialize(file)
|
40
48
|
@transactions = []
|
49
|
+
@bank = self.class.to_s.split('::').last
|
50
|
+
@bank = 'Unknown' if @bank == 'Base'
|
41
51
|
@lines = file.readlines
|
42
52
|
end
|
43
53
|
|
@@ -52,7 +62,7 @@ module MT940
|
|
52
62
|
def parse_tag_61
|
53
63
|
if @line.match(/^:61:(\d{6})(C|D)(\d+),(\d{0,2})/)
|
54
64
|
type = $2 == 'D' ? -1 : 1
|
55
|
-
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f)
|
65
|
+
@transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f, :bank => @bank)
|
56
66
|
@transaction.date = parse_date($1)
|
57
67
|
@transactions << @transaction
|
58
68
|
@tag86 = false
|
data/lib/mt940/transaction.rb
CHANGED
@@ -2,10 +2,11 @@ module MT940
|
|
2
2
|
|
3
3
|
class Transaction
|
4
4
|
|
5
|
-
attr_accessor :bank_account, :contra_account, :amount, :description, :contra_account_owner, :date
|
5
|
+
attr_accessor :bank_account, :contra_account, :amount, :description, :contra_account_owner, :date, :bank
|
6
6
|
|
7
7
|
def initialize(attributes = {})
|
8
8
|
@bank_account = attributes[:bank_account]
|
9
|
+
@bank = attributes[:bank]
|
9
10
|
@amount = attributes[:amount]
|
10
11
|
@description = attributes[:description]
|
11
12
|
@date = attributes[:date]
|
data/mt940.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mt940}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["dovadi"]
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"test/fixtures/ing.txt",
|
38
38
|
"test/fixtures/rabobank.txt",
|
39
39
|
"test/fixtures/triodos.txt",
|
40
|
+
"test/fixtures/unknown.txt",
|
40
41
|
"test/helper.rb",
|
41
42
|
"test/test_mt940_abnamro.rb",
|
42
43
|
"test/test_mt940_base.rb",
|
@@ -0,0 +1,22 @@
|
|
1
|
+
940 00
|
2
|
+
:20:MPBZ
|
3
|
+
:25:0001234567
|
4
|
+
:28C:000
|
5
|
+
:60F:C100722EUR0,00
|
6
|
+
:61:100722D25,03NOV NONREF
|
7
|
+
:86: RC AFREKENING BETALINGSVERKEER
|
8
|
+
BETREFT REKENING 4715589 PERIODE: 01-10-2010 / 31-12-2010
|
9
|
+
ING Bank N.V. tarifering ING
|
10
|
+
:61:100722D3,03NOV NONREF
|
11
|
+
:86:0111111111 GPSEOUL SPOEDBETALING MPBZS1016000047 GPSEOUL
|
12
|
+
:61:100722D1,11NGT TMG TANGO
|
13
|
+
:86:0111111111 ING iDEAL KN: TMG TANGO TRANSACTIENR 0050000534527978 10062010 15:32 TMG TANGO ING Bank inzake GPKyoto
|
14
|
+
:61:100722D20,00NGM NONREF
|
15
|
+
:86: ABN AMRO BANK>AMSTERDAM 22072010 09:57 002 5595781
|
16
|
+
:61:100722D1,10NGT NONREF
|
17
|
+
:86:0111111111 GPPeking 170000001AC
|
18
|
+
:61:100722C3,68NVZ NONREF
|
19
|
+
:86:0111111111 EJ46GREENP100610T1456 CLIEOP TMG GPHONGKONG AMSTERDAM
|
20
|
+
:62F:C100723EUR3,47
|
21
|
+
:86:D000004C000002D25,24C28,71
|
22
|
+
-XXX
|
data/test/test_mt940_abnamro.rb
CHANGED
data/test/test_mt940_base.rb
CHANGED
@@ -2,40 +2,50 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestMt940Base < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
context 'MT940::Base' do
|
6
|
+
should 'read the transactions with the filename of the MT940 file' do
|
7
|
+
file_name = File.dirname(__FILE__) + '/fixtures/ing.txt'
|
8
|
+
@transactions = MT940::Base.transactions(file_name)
|
9
|
+
assert_equal 6, @transactions.size
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
should 'read the transactions with the handle to the mt940 file itself' do
|
13
|
+
file_name = File.dirname(__FILE__) + '/fixtures/ing.txt'
|
14
|
+
file = File.open(file_name)
|
15
|
+
@transactions = MT940::Base.transactions(file)
|
16
|
+
assert_equal 6, @transactions.size
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
#Tempfile is used by Paperclip, so the following will work:
|
20
|
+
#MT940::Base.transactions(@mt940_file.attachment.to_file)
|
21
|
+
should 'read the transactions with the handle of a Tempfile' do
|
22
|
+
file = Tempfile.new('temp')
|
23
|
+
file.write(':940:')
|
24
|
+
file.rewind
|
25
|
+
@transactions = MT940::Base.transactions(file)
|
26
|
+
assert_equal 0, @transactions.size
|
27
|
+
file.unlink
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
should 'raise an exception if the file does not exist' do
|
31
|
+
file_name = File.dirname(__FILE__) + '/fixtures/123.txt'
|
32
|
+
assert_raise Errno::ENOENT do
|
33
|
+
@transactions = MT940::Base.transactions(file_name)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'raise an ArgumentError if a wrong argument was given' do
|
38
|
+
assert_raise ArgumentError do
|
39
|
+
MT940::Base.transactions(Hash.new)
|
40
|
+
end
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
|
44
|
+
context 'Unknown MT940 file' do
|
45
|
+
should 'return its bank' do
|
46
|
+
file_name = File.dirname(__FILE__) + '/fixtures/unknown.txt'
|
47
|
+
@transactions = MT940::Base.transactions(file_name)
|
48
|
+
assert_equal 'Unknown', @transactions.first.bank
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
data/test/test_mt940_ing.rb
CHANGED
data/test/test_mt940_rabobank.rb
CHANGED
data/test/test_mt940_triodos.rb
CHANGED
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
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- dovadi
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- test/fixtures/ing.txt
|
88
88
|
- test/fixtures/rabobank.txt
|
89
89
|
- test/fixtures/triodos.txt
|
90
|
+
- test/fixtures/unknown.txt
|
90
91
|
- test/helper.rb
|
91
92
|
- test/test_mt940_abnamro.rb
|
92
93
|
- test/test_mt940_base.rb
|