mt940parser 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -3
- data/lib/mt940parser/document.treetop +0 -1
- data/lib/mt940parser/node_extensions.rb +47 -16
- data/lib/mt940parser/parser.rb +1 -1
- data/lib/mt940parser/version.rb +1 -1
- data/mt940parser.gemspec +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# MT940Parser
|
2
2
|
|
3
|
-
|
3
|
+
A parser written in Treetop for handling files in MT940 format. The format is widely used in
|
4
|
+
Europe by banks and it contains information about client account statements for a given time period.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -18,7 +19,17 @@ Or install it yourself as:
|
|
18
19
|
|
19
20
|
## Usage
|
20
21
|
|
21
|
-
|
22
|
+
result = MT940::Parser.parse(string)
|
23
|
+
|
24
|
+
Now you can do some cool stuff like list all records:
|
25
|
+
|
26
|
+
result.elements #=>
|
27
|
+
|
28
|
+
Or list all transactions for a given record:
|
29
|
+
|
30
|
+
result.elements.first.transactions
|
31
|
+
|
32
|
+
More to come
|
22
33
|
|
23
34
|
## Contributing
|
24
35
|
|
@@ -1,30 +1,27 @@
|
|
1
1
|
module Document
|
2
2
|
|
3
3
|
class Transaction < Treetop::Runtime::SyntaxNode
|
4
|
-
def
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def policy_numbers
|
9
|
-
details.scan(/\d{3,}/)
|
4
|
+
def to_hash
|
5
|
+
base.to_hash.merge(statement.to_hash)
|
10
6
|
end
|
11
7
|
end
|
12
8
|
|
13
9
|
class All < Treetop::Runtime::SyntaxNode
|
14
|
-
|
15
|
-
|
10
|
+
|
11
|
+
def to_hash
|
12
|
+
elements.map(&:to_hash)
|
16
13
|
end
|
17
14
|
|
18
|
-
def
|
19
|
-
|
15
|
+
def transactions
|
16
|
+
elements.flat_map(&:to_hash)
|
20
17
|
end
|
21
18
|
|
22
|
-
def
|
23
|
-
|
19
|
+
def transactions_credit
|
20
|
+
transactions.select{ |t| t[:type] == :credit}
|
24
21
|
end
|
25
22
|
|
26
|
-
def
|
27
|
-
|
23
|
+
def transactions_debit
|
24
|
+
transactions.select{ |t| t[:type] == :debit }
|
28
25
|
end
|
29
26
|
|
30
27
|
# Utility
|
@@ -33,16 +30,27 @@ module Document
|
|
33
30
|
end
|
34
31
|
end
|
35
32
|
class Transactions < Treetop::Runtime::SyntaxNode
|
33
|
+
def to_hash
|
34
|
+
elements.flat_map(&:to_hash)
|
35
|
+
end
|
36
36
|
end
|
37
37
|
class Statement < Treetop::Runtime::SyntaxNode
|
38
38
|
end
|
39
39
|
class Record < Treetop::Runtime::SyntaxNode
|
40
|
-
def
|
41
|
-
elements.
|
40
|
+
def to_hash
|
41
|
+
elements.select{ |e| e.class == Document::Transactions }.flat_map(&:to_hash)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
class Base < Treetop::Runtime::SyntaxNode
|
46
|
+
def to_hash
|
47
|
+
{
|
48
|
+
valor: valor.text_value,
|
49
|
+
account_date: account_date.text_value,
|
50
|
+
type: type.val,
|
51
|
+
amount: amount.val
|
52
|
+
}
|
53
|
+
end
|
46
54
|
end
|
47
55
|
class Digit < Treetop::Runtime::SyntaxNode
|
48
56
|
end
|
@@ -55,6 +63,9 @@ module Document
|
|
55
63
|
class AccountDate < Treetop::Runtime::SyntaxNode
|
56
64
|
end
|
57
65
|
class Type < Treetop::Runtime::SyntaxNode
|
66
|
+
def val
|
67
|
+
text_value == 'C' ? :credit : :debit
|
68
|
+
end
|
58
69
|
end
|
59
70
|
class Amount < Treetop::Runtime::SyntaxNode
|
60
71
|
def val
|
@@ -62,11 +73,18 @@ module Document
|
|
62
73
|
end
|
63
74
|
end
|
64
75
|
class NotImplemented < Treetop::Runtime::SyntaxNode
|
76
|
+
def to_hash
|
77
|
+
{}
|
78
|
+
end
|
65
79
|
end
|
66
80
|
class NewLine < Treetop::Runtime::SyntaxNode
|
67
81
|
end
|
68
82
|
|
69
83
|
class Date < Treetop::Runtime::SyntaxNode
|
84
|
+
def to_hash
|
85
|
+
{}
|
86
|
+
end
|
87
|
+
|
70
88
|
def val
|
71
89
|
text_value.strip[4..-1]
|
72
90
|
end
|
@@ -80,12 +98,25 @@ module R86
|
|
80
98
|
class Mark < Treetop::Runtime::SyntaxNode
|
81
99
|
end
|
82
100
|
class Description < Treetop::Runtime::SyntaxNode
|
101
|
+
def val
|
102
|
+
text_value.strip[3..-1]
|
103
|
+
end
|
83
104
|
end
|
84
105
|
class Details < Treetop::Runtime::SyntaxNode
|
106
|
+
def val
|
107
|
+
text_value.strip[3..-1]
|
108
|
+
end
|
85
109
|
end
|
86
110
|
class Detail < Treetop::Runtime::SyntaxNode
|
87
111
|
end
|
88
112
|
class Statement < Treetop::Runtime::SyntaxNode
|
113
|
+
def to_hash
|
114
|
+
{
|
115
|
+
code: code.text_value,
|
116
|
+
description: description.val,
|
117
|
+
details: details.val
|
118
|
+
}
|
119
|
+
end
|
89
120
|
end
|
90
121
|
class Code < Treetop::Runtime::SyntaxNode
|
91
122
|
end
|
data/lib/mt940parser/parser.rb
CHANGED
@@ -29,7 +29,7 @@ module MT940
|
|
29
29
|
def self.clean_tree(root_node)
|
30
30
|
return if(root_node.elements.nil?)
|
31
31
|
root_node.elements.delete_if{|node| node.class.name == "Treetop::Runtime::SyntaxNode" }
|
32
|
-
root_node.elements.delete_if{|node| node.class.name == "
|
32
|
+
root_node.elements.delete_if{|node| node.class.name == "Document::NewLine" } #remove nls
|
33
33
|
root_node.elements.delete_if{|node| node.class.name == "R86::Blank" } #remove nls
|
34
34
|
root_node.elements.each {|node| self.clean_tree(node) }
|
35
35
|
end
|
data/lib/mt940parser/version.rb
CHANGED
data/mt940parser.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = MT940::VERSION
|
9
9
|
spec.authors = ["Georgi Mitrev"]
|
10
10
|
spec.email = ["gvmitrev@gmail.com"]
|
11
|
-
spec.description = %q{MT940 parser}
|
11
|
+
spec.description = %q{(SWIFT)MT940 file parser}
|
12
12
|
spec.summary = %q{Parser for the (SWIFT)-MT940 format}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mt940parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: treetop
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
description: MT940 parser
|
78
|
+
description: (SWIFT)MT940 file parser
|
79
79
|
email:
|
80
80
|
- gvmitrev@gmail.com
|
81
81
|
executables: []
|