mt940_parser 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +3 -3
- data/lib/mt940.rb +24 -6
- data/mt940_parser.gemspec +11 -8
- data/test/fixtures/empty_entry_date.txt +2 -0
- data/test/fixtures/empty_entry_date.yml +9 -0
- data/test/fixtures/sepa_mt9401.yml +2149 -2228
- data/test/fixtures/with_binary_character.txt +27 -0
- data/test/fixtures/with_binary_character.yml +4 -0
- data/test/test_mt940.rb +17 -2
- metadata +73 -82
data/VERSION.yml
CHANGED
data/lib/mt940.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'mt940/customer_statement_message'
|
2
3
|
|
3
4
|
class MT940
|
@@ -76,9 +77,11 @@ class MT940
|
|
76
77
|
# 25
|
77
78
|
class Account < Field
|
78
79
|
attr_reader :bank_code, :account_number, :account_currency
|
79
|
-
|
80
|
+
|
81
|
+
CONTENT = /^(.{8,11})\/(\d{0,23})([A-Z]{3})?$/
|
82
|
+
|
80
83
|
def parse_content(content)
|
81
|
-
content.match(
|
84
|
+
content.match(CONTENT)
|
82
85
|
@bank_code, @account_number, @account_currency = $1, $2, $3
|
83
86
|
end
|
84
87
|
end
|
@@ -86,9 +89,11 @@ class MT940
|
|
86
89
|
# 28
|
87
90
|
class Statement < Field
|
88
91
|
attr_reader :number, :sheet
|
92
|
+
|
93
|
+
CONTENT = /^(0|(\d{5,5})\/(\d{2,5}))$/
|
89
94
|
|
90
95
|
def parse_content(content)
|
91
|
-
content.match(
|
96
|
+
content.match(CONTENT)
|
92
97
|
if $1 == '0'
|
93
98
|
@number = @sheet = 0
|
94
99
|
else
|
@@ -100,9 +105,11 @@ class MT940
|
|
100
105
|
# 60
|
101
106
|
class AccountBalance < Field
|
102
107
|
attr_reader :balance_type, :sign, :currency, :amount, :date
|
108
|
+
|
109
|
+
CONTENT = /^(C|D)(\w{6})(\w{3})(\d{1,12},\d{0,2})$/
|
103
110
|
|
104
111
|
def parse_content(content)
|
105
|
-
content.match(
|
112
|
+
content.match(CONTENT)
|
106
113
|
|
107
114
|
@balance_type = case @modifier
|
108
115
|
when 'F'
|
@@ -135,8 +142,10 @@ class MT940
|
|
135
142
|
class StatementLine < Field
|
136
143
|
attr_reader :date, :entry_date, :funds_code, :amount, :swift_code, :reference, :transaction_description
|
137
144
|
|
145
|
+
CONTENT = /^(\d{6})(\d{4})?(C|D|RC|RD)\D?(\d{1,12},\d{0,2})((?:N|F).{3})(NONREF|.{0,16})(?:$|\/\/)(.*)/
|
146
|
+
|
138
147
|
def parse_content(content)
|
139
|
-
content.match(
|
148
|
+
content.match(CONTENT)
|
140
149
|
|
141
150
|
raw_date = $1
|
142
151
|
raw_entry_date = $2
|
@@ -157,7 +166,7 @@ class MT940
|
|
157
166
|
@transaction_description = $7
|
158
167
|
|
159
168
|
@date = parse_date(raw_date)
|
160
|
-
@entry_date = parse_entry_date(raw_entry_date, @date)
|
169
|
+
@entry_date = parse_entry_date(raw_entry_date, @date) if raw_entry_date
|
161
170
|
end
|
162
171
|
|
163
172
|
def value_date
|
@@ -224,6 +233,15 @@ class MT940
|
|
224
233
|
|
225
234
|
class << self
|
226
235
|
def parse(text)
|
236
|
+
new_text = text.clone.force_encoding("ISO-8859-1")
|
237
|
+
if !new_text.valid_encoding?
|
238
|
+
warn "Your data is not in binary format"
|
239
|
+
new_text = text.clone.encode("ISO-8859-1")
|
240
|
+
if !new_text.valid_encoding?
|
241
|
+
puts "WOOOOT WHAT IS THE RIGHT ENCODING?"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
text = new_text # WOOOT refactor?
|
227
245
|
text << "\r\n" if text[-1,1] == '-'
|
228
246
|
raw_sheets = text.split(/^-\r\n/).map { |sheet| sheet.gsub(/\r\n(?!:)/, '') }
|
229
247
|
sheets = raw_sheets.map { |raw_sheet| parse_sheet(raw_sheet) }
|
data/mt940_parser.gemspec
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.0.
|
7
|
+
s.name = "mt940_parser"
|
8
|
+
s.version = "1.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Thies C. Arntzen", "Phillip Oertel"]
|
12
|
-
s.date =
|
13
|
-
s.email =
|
12
|
+
s.date = "2012-04-18"
|
13
|
+
s.email = "developers@betterplace.org"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
16
16
|
"README.rdoc"
|
@@ -39,6 +39,8 @@ Gem::Specification.new do |s|
|
|
39
39
|
"test/fixtures/currency_in_25.yml",
|
40
40
|
"test/fixtures/empty_86.txt",
|
41
41
|
"test/fixtures/empty_86.yml",
|
42
|
+
"test/fixtures/empty_entry_date.txt",
|
43
|
+
"test/fixtures/empty_entry_date.yml",
|
42
44
|
"test/fixtures/empty_line.txt",
|
43
45
|
"test/fixtures/empty_line.yml",
|
44
46
|
"test/fixtures/missing_crlf_at_end.txt",
|
@@ -47,15 +49,17 @@ Gem::Specification.new do |s|
|
|
47
49
|
"test/fixtures/sepa_mt9401.yml",
|
48
50
|
"test/fixtures/sepa_snippet.txt",
|
49
51
|
"test/fixtures/sepa_snippet_broken.txt",
|
52
|
+
"test/fixtures/with_binary_character.txt",
|
53
|
+
"test/fixtures/with_binary_character.yml",
|
50
54
|
"test/helper.rb",
|
51
55
|
"test/test_customer_statement_message.rb",
|
52
56
|
"test/test_mt940.rb"
|
53
57
|
]
|
54
|
-
s.homepage =
|
58
|
+
s.homepage = "http://github.com/betterplace/mt940_parser"
|
55
59
|
s.licenses = ["MIT"]
|
56
60
|
s.require_paths = ["lib"]
|
57
|
-
s.rubygems_version =
|
58
|
-
s.summary =
|
61
|
+
s.rubygems_version = "1.8.21"
|
62
|
+
s.summary = "MT940 parses account statements in the SWIFT MT940 format."
|
59
63
|
s.test_files = [
|
60
64
|
"test/helper.rb",
|
61
65
|
"test/test_customer_statement_message.rb",
|
@@ -63,7 +67,6 @@ Gem::Specification.new do |s|
|
|
63
67
|
]
|
64
68
|
|
65
69
|
if s.respond_to? :specification_version then
|
66
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
70
|
s.specification_version = 3
|
68
71
|
|
69
72
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|