camt_parser 2.3.6 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 237a24b5419befa6e615054bdffb5fbb83383a10
4
- data.tar.gz: 0b86d1d7dbf61653ff1ed30797f72a32a71858f9
3
+ metadata.gz: 6ee854a1a9177454ea4abd0fdf594fe85b695b8e
4
+ data.tar.gz: f92858b851635154a0bbf0469881ee695fbf8de5
5
5
  SHA512:
6
- metadata.gz: 8b6c6701362a33ce7501e1d586c8e785bd07815a2d1a119fe06f773ae2ab689eac5f3f5f9de084d16692b6b44258db80b893518f82a05e05a15ad3bfdfd10275
7
- data.tar.gz: 770a1f3b5de0f7b6af1090fea1c85159eda8f1907d8fdb83c36aaf417741a997c232e7f8690e7e90c33934093eb6e91a3371723758abb4f8a1f277b5c0cad300
6
+ metadata.gz: 9fd380768a96dbe8d449ba3378ca07594fc16f9d2f391ea9ca7d52b42aa2dd4d21e0536cee7641fc0430ee849896114d8b6d355c5841ed20bbfee9586239152a
7
+ data.tar.gz: 9ea12085d65528ce1be9760de4c114b7c9eaddbe8013fbdbfd909d4b80a48436e8847d842ffa377b0dac33faed8b072aab08eadeb2b4842c750729eb33947f74
data/lib/camt_parser.rb CHANGED
@@ -27,4 +27,5 @@ require_relative "camt_parser/054/notification"
27
27
  require_relative "camt_parser/054/base"
28
28
  require_relative "camt_parser/file"
29
29
  require_relative "camt_parser/string"
30
+ require_relative "camt_parser/register"
30
31
  require_relative "camt_parser/xml"
@@ -1,9 +1,8 @@
1
1
  module CamtParser
2
2
  module Errors
3
- class UnsupportedNamespaceError < StandardError
4
- end
5
-
6
- class NotXMLError < StandardError
7
- end
3
+ class NamespaceAlreadyRegistered < StandardError; end
4
+ class NotXMLError < StandardError; end
5
+ class UnsupportedParserClass < StandardError; end
6
+ class UnsupportedNamespaceError < StandardError; end
8
7
  end
9
8
  end
@@ -0,0 +1,13 @@
1
+ require_relative './xml'
2
+
3
+ # Add registrations
4
+ ## CAMT052
5
+ CamtParser::Xml.register('urn:iso:std:iso:20022:tech:xsd:camt.052.001.02', :camt052)
6
+
7
+ ## CAMT053
8
+ CamtParser::Xml.register('urn:iso:std:iso:20022:tech:xsd:camt.053.001.02', :camt053)
9
+ CamtParser::Xml.register('urn:iso:std:iso:20022:tech:xsd:camt.053.001.04', :camt053)
10
+
11
+ ## CAMT054
12
+ CamtParser::Xml.register('urn:iso:std:iso:20022:tech:xsd:camt.054.001.02', :camt054)
13
+ CamtParser::Xml.register('urn:iso:std:iso:20022:tech:xsd:camt.054.001.04', :camt054)
@@ -1,3 +1,3 @@
1
1
  module CamtParser
2
- VERSION = "2.3.6"
2
+ VERSION = "2.4.0"
3
3
  end
@@ -1,21 +1,39 @@
1
1
  module CamtParser
2
2
  class Xml
3
+ PARSER_MAPPING = {
4
+ camt052: CamtParser::Format052::Base,
5
+ camt053: CamtParser::Format053::Base,
6
+ camt054: CamtParser::Format054::Base
7
+ }.freeze
8
+
9
+ SUPPORTED_PARSERS = PARSER_MAPPING.keys.freeze
10
+
11
+ @namespace_parsers = {}
12
+
13
+ def self.register(namespace, parser)
14
+ if !SUPPORTED_PARSERS.include?(parser)
15
+ raise CamtParser::Errors::UnsupportedParserClass, parser.to_s
16
+ end
17
+
18
+ if @namespace_parsers.key?(namespace) # Prevent overwriting existing registrations
19
+ raise CamtParser::Errors::NamespaceAlreadyRegistered, namespace
20
+ end
21
+
22
+ @namespace_parsers[namespace] = PARSER_MAPPING[parser]
23
+ end
24
+
3
25
  def self.parse(doc)
4
26
  raise CamtParser::Errors::NotXMLError, doc.class unless doc.is_a? Nokogiri::XML::Document
5
27
 
6
- namespaces = doc.namespaces['xmlns']
28
+ namespace = doc.namespaces['xmlns']
7
29
  doc.remove_namespaces!
8
30
 
9
- case namespaces
10
- when 'urn:iso:std:iso:20022:tech:xsd:camt.052.001.02'
11
- return CamtParser::Format052::Base.new(doc.xpath('Document'))
12
- when 'urn:iso:std:iso:20022:tech:xsd:camt.053.001.02', 'urn:iso:std:iso:20022:tech:xsd:camt.053.001.04'
13
- return CamtParser::Format053::Base.new(doc.xpath('Document'))
14
- when 'urn:iso:std:iso:20022:tech:xsd:camt.054.001.02', 'urn:iso:std:iso:20022:tech:xsd:camt.054.001.04'
15
- return CamtParser::Format054::Base.new(doc.xpath('Document'))
16
- else
17
- raise CamtParser::Errors::UnsupportedNamespaceError, namespaces
31
+ parser_class = @namespace_parsers[namespace]
32
+ if parser_class == nil
33
+ raise CamtParser::Errors::UnsupportedNamespaceError, namespace
18
34
  end
35
+
36
+ return parser_class.new(doc.xpath('Document'))
19
37
  end
20
38
  end
21
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camt_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.6
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-10 00:00:00.000000000 Z
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
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
55
  - !ruby/object:Gem::Dependency
70
56
  name: nokogiri
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +95,7 @@ files:
109
95
  - lib/camt_parser/general/type/code.rb
110
96
  - lib/camt_parser/general/type/proprietary.rb
111
97
  - lib/camt_parser/misc.rb
98
+ - lib/camt_parser/register.rb
112
99
  - lib/camt_parser/string.rb
113
100
  - lib/camt_parser/version.rb
114
101
  - lib/camt_parser/xml.rb