mt940 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ * 0.3.0
2
+
3
+ - Added a date to a transaction
4
+ - Change transaction attribute name of contra_account_name into contra_account_owner
5
+
1
6
  * 0.2.0
2
7
 
3
8
  - General parse method refactored and broke down in individual parse methods per tag
data/README.md CHANGED
@@ -13,12 +13,18 @@ The following Dutch banks are implemented:
13
13
  Usage
14
14
  =====
15
15
 
16
- `file_name = File.dirname(__FILE__) + 'ing.940'`
16
+ file_name = File.dirname(__FILE__) + 'ing.940'
17
17
 
18
- `@transactions = MT940:::Base.transactions(file_name)`
18
+ @transactions = MT940:::Base.transactions(file_name)
19
19
 
20
- * Independent of the bank, a transaction always consists of an amount and a description.
21
- * With some implementations the contra_account with its owner is extracted as well.
20
+ * Independent of the bank, a transaction always consists of:
21
+
22
+ - accountnumber
23
+ - date
24
+ - amount (which is negative in case of a withdrawal)
25
+ - description
26
+
27
+ * With the Rabobank the contra_account with its owner is extracted as well.
22
28
 
23
29
 
24
30
  Contributing to MT940
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -1,9 +1,10 @@
1
1
  class MT940::Abnamro < MT940::Base
2
2
 
3
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)
4
+ if @line.match(/^:61:(\d{6})\d{4}(C|D)(\d+),(\d{0,2})/)
5
+ type = $2 == 'D' ? -1 : 1
6
+ @transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f)
7
+ @transaction.date = parse_date($1)
7
8
  @transactions << @transaction
8
9
  @tag86 = false
9
10
  end
@@ -1,11 +1,12 @@
1
1
  class MT940::Rabobank < MT940::Base
2
2
 
3
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
4
+ if @line.match(/^:61:(\d{6})(C|D)(\d+),(\d{0,2})\w{4}(.{16})(.+)$/)
5
+ type = $2 == 'D' ? -1 : 1
6
+ @transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f)
7
+ @transaction.date = parse_date($1)
8
+ @transaction.contra_account = $5.strip
9
+ @transaction.contra_account_owner = $6.strip
9
10
  @transactions << @transaction
10
11
  end
11
12
  end
data/lib/mt940/base.rb CHANGED
@@ -46,6 +46,7 @@ module MT940
46
46
  if @line.match(/^:61:(\d{6})(C|D)(\d+),(\d{0,2})/)
47
47
  type = $2 == 'D' ? -1 : 1
48
48
  @transaction = MT940::Transaction.new(:bank_account => @bank_account, :amount => type * ($3 + '.' + $4).to_f)
49
+ @transaction.date = parse_date($1)
49
50
  @transactions << @transaction
50
51
  @tag86 = false
51
52
  end
@@ -62,6 +63,10 @@ module MT940
62
63
  @transaction.description += ' ' + @line.gsub(/\n/,'').gsub(/>\d{2}/,'') if @tag86
63
64
  end
64
65
 
66
+ def parse_date(string)
67
+ Date.new(2000 + string[0..1].to_i, string[2..3].to_i, string[4..5].to_i) if string
68
+ end
69
+
65
70
  #Fail silently
66
71
  def method_missing(*args)
67
72
  end
@@ -2,13 +2,15 @@ module MT940
2
2
 
3
3
  class Transaction
4
4
 
5
- attr_accessor :bank_account, :contra_account, :amount, :description, :contra_account_name
5
+ attr_accessor :bank_account, :contra_account, :amount, :description, :contra_account_owner, :date
6
6
 
7
7
  def initialize(attributes = {})
8
8
  @bank_account = attributes[:bank_account]
9
9
  @amount = attributes[:amount]
10
10
  @description = attributes[:description]
11
- @contra_account_name = attributes[:contra_account_name]
11
+ @date = attributes[:date]
12
+ @contra_account = attributes[:contra_account]
13
+ @contra_account_name = attributes[:contra_account_owner]
12
14
  end
13
15
 
14
16
  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.2.0"
8
+ s.version = "0.3.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"]
12
- s.date = %q{2011-06-24}
12
+ s.date = %q{2011-06-27}
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 = [
@@ -24,6 +24,11 @@ class TestMt940Abnamro < Test::Unit::TestCase
24
24
  should 'have a description' do
25
25
  assert_equal 'GIRO 428428 KPN - DIGITENNE BETALINGSKENM. 000000042188659 5314606715 BETREFT FACTUUR D.D. 20-05-2011 INCL. 1,44 BTW', @transaction.description
26
26
  end
27
+
28
+ should 'have a date' do
29
+ assert_equal Date.new(2011,5,24), @transaction.date
30
+ end
31
+
27
32
  end
28
33
 
29
34
  end
@@ -24,6 +24,10 @@ class TestMt940Ing < Test::Unit::TestCase
24
24
  should 'have a description' do
25
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
26
  end
27
+
28
+ should 'have a date' do
29
+ assert_equal Date.new(2010,7,22), @transaction.date
30
+ end
27
31
  end
28
32
 
29
33
  end
@@ -25,13 +25,18 @@ class TestMt940Rabobank < Test::Unit::TestCase
25
25
  assert_equal -77.35, @transaction.amount
26
26
  end
27
27
 
28
- should 'have a contra_account_name' do
29
- assert_equal 'Uitgeverij De Druif', @transaction.contra_account_name
28
+ should 'have a contra_account_owner' do
29
+ assert_equal 'Uitgeverij De Druif', @transaction.contra_account_owner
30
30
  end
31
31
 
32
32
  should 'have a description' do
33
33
  assert_equal 'Factuurnummer 234578', @transaction.description
34
34
  end
35
+
36
+ should 'have a date' do
37
+ assert_equal Date.new(2011,6,15), @transaction.date
38
+ end
39
+
35
40
  end
36
41
 
37
42
  end
@@ -24,6 +24,11 @@ class TestMt940Triodos < Test::Unit::TestCase
24
24
  should 'have a description' do
25
25
  assert_equal '0000000000000 ALGEMENE TUSSENREKENING KOSTEN VAN 01-10-2010 TOT EN M ET 31-12-20100390123456', @transaction.description
26
26
  end
27
+
28
+ should 'have a date' do
29
+ assert_equal Date.new(2011,1,1), @transaction.date
30
+ end
31
+
27
32
  end
28
33
 
29
34
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.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-24 00:00:00 +02:00
17
+ date: 2011-06-27 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency