camt_parser 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/camt_parser/053/base.rb +14 -0
- data/lib/camt_parser/053/group_header.rb +29 -0
- data/lib/camt_parser/053/statement.rb +75 -0
- data/lib/camt_parser/file.rb +17 -0
- data/lib/camt_parser/version.rb +3 -0
- data/lib/camt_parser.rb +9 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d05e17d91aaedeaf9a6f1973248329b4b79a880
|
4
|
+
data.tar.gz: 72c4fcd51b6b6d1303090ffa7699616b5705c7b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b36ca72815e182bf7e8a7ca0f30d0e4ae6e26abd591c0cfb295ba91ddcc74f83671f2a96b77e95395f9627114a60baf71d6794da01f6ab1966b6f3401c97812e
|
7
|
+
data.tar.gz: 60ba5d68f92a309cea026895e733ff15c1c3230e1dd48d9ba416fba7b6f69b66faeba96df9ac42486bf3151b62c04230c0ca088a127e03a3cd8a7dc929214137
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module CamtParser
|
2
|
+
module Format053
|
3
|
+
class Base
|
4
|
+
attr_reader :group_header, :statements
|
5
|
+
|
6
|
+
def initialize(xml_data)
|
7
|
+
grphdr = xml_data.xpath('BkToCstmrStmt/GrpHdr')
|
8
|
+
@group_header = GroupHeader.new(grphdr)
|
9
|
+
statements = xml_data.xpath('BkToCstmrStmt/Stmt')
|
10
|
+
@statements = statements.map{ |x| Statement.new(x) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module CamtParser
|
4
|
+
module Format053
|
5
|
+
class GroupHeader
|
6
|
+
attr_reader :message_id, :creation_date_time, :additional_information, :message_pagination
|
7
|
+
|
8
|
+
def initialize(xml_data)
|
9
|
+
@message_id = xml_data.xpath('MsgId').first.content
|
10
|
+
@creation_date_time = Time.parse(xml_data.xpath('CreDtTm').first.content)
|
11
|
+
@message_pagination = (x = xml_data.xpath('MsgPgntn')).empty? ? nil : MessagePagination.new(x)
|
12
|
+
@additional_information = (x = xml_data.xpath('AddtlInf')).empty? ? nil : x.first.content
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MessagePagination
|
17
|
+
attr_reader :page_number
|
18
|
+
|
19
|
+
def initialize(xml_data)
|
20
|
+
@page_number = xml_data.xpath('PgNb').first.content.to_i
|
21
|
+
@last_page_indicator = xml_data.xpath('LastPgInd').first.content == 'true'
|
22
|
+
end
|
23
|
+
|
24
|
+
def last_page?
|
25
|
+
@last_page_indicator
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'bigdecimal'
|
3
|
+
|
4
|
+
module CamtParser
|
5
|
+
module Format053
|
6
|
+
class Statement
|
7
|
+
attr_reader :identification, :creation_date_time, :from_date_time, :to_date_time,
|
8
|
+
:account, :entries
|
9
|
+
|
10
|
+
def initialize(xml_data)
|
11
|
+
@identification = (x = xml_data.xpath('Id')).empty? ? nil : x.first.content
|
12
|
+
@creation_date_time = Time.parse(xml_data.xpath('CreDtTm').first.content)
|
13
|
+
@from_date_time = (x = xml_data.xpath('FrToDt/FrDtTm')).empty? ? nil : Time.parse(x.first.content)
|
14
|
+
@to_date_time = (x = xml_data.xpath('FrToDt/ToDtTm')).empty? ? nil : Time.parse(x.first.content)
|
15
|
+
@account = Account.new(xml_data.xpath('Acct').first)
|
16
|
+
@entries = xml_data.xpath('Ntry').map{ |x| Entry.new(x) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Entry
|
21
|
+
attr_reader :amount, :currency, :value_date, :debitor, :creditor, :remittance_information
|
22
|
+
|
23
|
+
def initialize(xml_data)
|
24
|
+
@amount = BigDecimal.new(xml_data.xpath('Amt').first.content)
|
25
|
+
@currency = xml_data.xpath('Amt/@Ccy').first.content
|
26
|
+
@debit = xml_data.xpath('CdtDbtInd').first.content.upcase == 'DBIT'
|
27
|
+
@value_date = Date.parse(xml_data.xpath('ValDt/Dt').first.content)
|
28
|
+
@creditor = Creditor.new(xml_data.xpath('NtryDtls'))
|
29
|
+
@debitor = Debitor.new(xml_data.xpath('NtryDtls'))
|
30
|
+
# Makes the assumption that only unstructured remittance information will be given
|
31
|
+
if (x = xml_data.xpath('NtryDtls/TxDtls/RmtInf/Ustrd')).empty?
|
32
|
+
@remittance_information = nil
|
33
|
+
else
|
34
|
+
@remittance_information = x.collect(&:content).join(' ')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def debit?
|
39
|
+
@debit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Account
|
44
|
+
attr_reader :iban, :bic, :bank_name
|
45
|
+
|
46
|
+
def initialize(xml_data)
|
47
|
+
@iban = (x = xml_data.xpath('Id/IBAN')).empty? ? nil : x.first.content
|
48
|
+
@bic = (x = xml_data.xpath('Svcr/FinInstnId/BIC')).empty? ? nil : x.first.content
|
49
|
+
@bank_name = (x = xml_data.xpath('Svcr/FinInstnId/Nm')).empty? ? nil : x.first.content
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Debitor
|
54
|
+
attr_reader :iban, :bic, :bank_name, :name
|
55
|
+
|
56
|
+
def initialize(xml_data)
|
57
|
+
@name = (x = xml_data.xpath('TxDtls/RltdPties/Dbtr/Nm')).empty? ? nil : x.first.content
|
58
|
+
@iban = (x = xml_data.xpath('TxDtls/RltdPties/DbtrAcct/Id/IBAN')).empty? ? nil : x.first.content
|
59
|
+
@bic = (x = xml_data.xpath('TxDtls/RltdAgts/DbtrAgt/FinInstnId/BIC')).empty? ? nil : x.first.content
|
60
|
+
@bank_name = (x = xml_data.xpath('TxDtls/RltdAgts/DbtrAgt/FinInstnId/Nm')).empty? ? nil : x.first.content
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Creditor
|
65
|
+
attr_reader :iban, :bic, :bank_name, :name
|
66
|
+
|
67
|
+
def initialize(xml_data)
|
68
|
+
@name = (x = xml_data.xpath('TxDtls/RltdPties/Cdtr/Nm')).empty? ? nil : x.first.content
|
69
|
+
@iban = (x = xml_data.xpath('TxDtls/RltdPties/CdtrAcct/Id/IBAN')).empty? ? nil : x.first.content
|
70
|
+
@bic = (x = xml_data.xpath('TxDtls/RltdAgts/CdtrAgt/FinInstnId/BIC')).empty? ? nil : x.first.content
|
71
|
+
@bank_name = (x = xml_data.xpath('TxDtls/RltdAgts/CdtrAgt/FinInstnId/Nm')).empty? ? nil : x.first.content
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CamtParser
|
2
|
+
class File
|
3
|
+
def self.parse(path)
|
4
|
+
f = ::File.open(path)
|
5
|
+
doc = Nokogiri::XML(f)
|
6
|
+
f.close
|
7
|
+
|
8
|
+
case doc.namespaces["xmlns"]
|
9
|
+
when "urn:iso:std:iso:20022:tech:xsd:camt.053.001.02"
|
10
|
+
doc.remove_namespaces!
|
11
|
+
return CamtParser::Format053::Base.new(doc.xpath("Document"))
|
12
|
+
else
|
13
|
+
raise "unknown or unsupported namespace: #{doc.namespaces["xlmns"]}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/camt_parser.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: camt_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Schoknecht
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 10.4.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 10.4.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.3.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: builder
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec_junit_formatter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.6.6.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.6.6.2
|
83
|
+
description: A parser for the Camt file format
|
84
|
+
email:
|
85
|
+
- tobias.schoknecht@barzahlen.de
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- lib/camt_parser.rb
|
91
|
+
- lib/camt_parser/053/base.rb
|
92
|
+
- lib/camt_parser/053/group_header.rb
|
93
|
+
- lib/camt_parser/053/statement.rb
|
94
|
+
- lib/camt_parser/file.rb
|
95
|
+
- lib/camt_parser/version.rb
|
96
|
+
homepage: ''
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.6
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Gem for parsing camt files into a speaking object.
|
120
|
+
test_files: []
|