mt940 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,10 +13,21 @@ The following Dutch banks are implemented:
13
13
  Usage
14
14
  =====
15
15
 
16
- file_name = File.dirname(__FILE__) + 'ing.940'
16
+ With the file name as argument:
17
+
18
+ file_name = '/Users/dovadi/Downloads/ing.940'
17
19
 
18
20
  @transactions = MT940:::Base.transactions(file_name)
19
21
 
22
+ or with the file itself:
23
+
24
+ file_name = '/Users/dovadi/Downloads/ing.940'
25
+
26
+ file = File.open(file_name)
27
+
28
+ @transactions = MT940:::Base.transactions(file)
29
+
30
+
20
31
  * Independent of the bank, a transaction always consists of:
21
32
 
22
33
  - accountnumber
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/lib/mt940/base.rb CHANGED
@@ -2,20 +2,15 @@ module MT940
2
2
 
3
3
  class Base
4
4
 
5
- def self.transactions(file_name)
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
5
+ def self.transactions(file)
6
+ file = File.open(file) if file.is_a?(String)
7
+ if file.is_a?(File)
8
+ instance = determine_bank(file.readline).new(file)
9
+ file.close
10
+ instance.parse
13
11
  else
14
- self
12
+ raise ArgumentError.new('No file is given!')
15
13
  end
16
- instance = klass.new(file_name)
17
- instance.parse
18
- instance.instance_variable_get('@transactions')
19
14
  end
20
15
 
21
16
  def parse
@@ -29,9 +24,21 @@ module MT940
29
24
 
30
25
  private
31
26
 
32
- def initialize(file_name)
27
+ def self.determine_bank(first_line)
28
+ if first_line.match(/INGBNL/)
29
+ ING
30
+ elsif first_line.match(/ABNANL/)
31
+ Abnamro
32
+ elsif first_line.match(/^:940:/)
33
+ Rabobank
34
+ else
35
+ self
36
+ end
37
+ end
38
+
39
+ def initialize(file)
33
40
  @transactions = []
34
- @lines = File.readlines(file_name)
41
+ @lines = file.readlines
35
42
  end
36
43
 
37
44
  def parse_tag_25
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.3.0"
8
+ s.version = "0.4.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-27}
12
+ s.date = %q{2011-07-04}
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 = [
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
39
39
  "test/fixtures/triodos.txt",
40
40
  "test/helper.rb",
41
41
  "test/test_mt940_abnamro.rb",
42
+ "test/test_mt940_base.rb",
42
43
  "test/test_mt940_ing.rb",
43
44
  "test/test_mt940_rabobank.rb",
44
45
  "test/test_mt940_triodos.rb"
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ class TestMt940Base < Test::Unit::TestCase
4
+
5
+ should 'read the transactions with the filename of the MT940 file' do
6
+ file_name = File.dirname(__FILE__) + '/fixtures/ing.txt'
7
+ @transactions = MT940::Base.transactions(file_name)
8
+ assert_equal 6, @transactions.size
9
+ end
10
+
11
+ should 'read the transactions with the handle to the mt940 file itself' do
12
+ file_name = File.dirname(__FILE__) + '/fixtures/ing.txt'
13
+ file = File.open(file_name)
14
+ @transactions = MT940::Base.transactions(file)
15
+ assert_equal 6, @transactions.size
16
+ end
17
+
18
+ should 'raise an exception if the file does not exist' do
19
+ file_name = File.dirname(__FILE__) + '/fixtures/123.txt'
20
+ assert_raise Errno::ENOENT do
21
+ @transactions = MT940::Base.transactions(file_name)
22
+ end
23
+ end
24
+
25
+ should 'raise an ArgumentError if a wrong argument was given' do
26
+ assert_raise ArgumentError do
27
+ MT940::Base.transactions(Hash.new)
28
+ end
29
+ end
30
+
31
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
7
+ - 4
8
8
  - 0
9
- version: 0.3.0
9
+ version: 0.4.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-27 00:00:00 +02:00
17
+ date: 2011-07-04 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -89,6 +89,7 @@ files:
89
89
  - test/fixtures/triodos.txt
90
90
  - test/helper.rb
91
91
  - test/test_mt940_abnamro.rb
92
+ - test/test_mt940_base.rb
92
93
  - test/test_mt940_ing.rb
93
94
  - test/test_mt940_rabobank.rb
94
95
  - test/test_mt940_triodos.rb