cxml-ruby 0.4.1 → 0.5.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
  SHA256:
3
- metadata.gz: 38b4bf64619173383fb1d6bbb76d1877bc70746752d884b6f9d79f967fcb70c0
4
- data.tar.gz: 2f42907da9ebe23561a44f0a39ac1143e32660b465c5b19cea13dbbcd1328ee4
3
+ metadata.gz: a5aed2303e25923bfa9f60fc5f0156f277df0f08a4f5d2c1f86598f762d273f6
4
+ data.tar.gz: 3a613e2eb5e2a6873e861624942ea04242f25f61ef883c5ab05925e16f4a7659
5
5
  SHA512:
6
- metadata.gz: 18ab3bad5fb8231724c14e29eb19c71ed1abdca1c9efd45832de27d46125070a705790a7813926f2f21273fdc010238de30d2405a251bcc28af389f5e075db76
7
- data.tar.gz: 5b3206398d10770f12215be79a4f6877db2d6efafc9679e31cc08a756384247466c90cd061b3f044befbfc39e631f35cb0029f83792dce69220e9ca75e05347d
6
+ metadata.gz: a6a49b19ccd68bf63238deae57a4b07df188458bdb5684064d2f0bb5d8c4be7e98bb281dbab6a0660a4e41e462a80e620887df43e27691d8ea87d5e410bc4c54
7
+ data.tar.gz: bd436f24c35a1fe90ebfc9ca83d5544b3341c604a73faf3381783ecf32b9d2755bcd2fdb0115c30f3d0fe1fc9442cd55da44f4e4a7dec040551319a1eedf6d4c
data/CHANGELOG.md CHANGED
@@ -14,9 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
14
 
15
15
  ---
16
16
 
17
- ## [0.4.1] - 2020-04-20
18
- ### Changed
19
- - Cast all node content values to strings before passing to Ox serializer.
17
+ ## [0.5.0] - 2020-04-30
18
+ ### Added
19
+ - Support parsing and specifying different DTDs.
20
20
 
21
21
  ## [0.4.0] - 2020-04-20
22
22
  ### Changed
data/lib/cxml/document.rb CHANGED
@@ -3,10 +3,11 @@
3
3
  module CXML
4
4
  class Document < DocumentNode
5
5
  accessible_attributes %i[
6
- version
6
+ dtd
7
7
  payload_id
8
- xml_lang
9
8
  timestamp
9
+ version
10
+ xml_lang
10
11
  ]
11
12
  accessible_nodes %i[
12
13
  header
@@ -27,6 +28,10 @@ module CXML
27
28
  @version ||= '1.2.037'
28
29
  end
29
30
 
31
+ def dtd
32
+ @dtd ||= 'cXML'
33
+ end
34
+
30
35
  # Check if document is request
31
36
  # @return [Boolean]
32
37
  def request?
@@ -62,7 +67,7 @@ module CXML
62
67
  private
63
68
 
64
69
  def dtd_url
65
- "http://xml.cxml.org/schemas/cXML/#{version}/cXML.dtd"
70
+ "http://xml.cxml.org/schemas/cXML/#{version}/#{dtd}.dtd"
66
71
  end
67
72
 
68
73
  def ox_doc
data/lib/cxml/parser.rb CHANGED
@@ -11,15 +11,37 @@ module CXML
11
11
 
12
12
  def parse
13
13
  @parsed_data = node_to_hash document
14
+ if dtd_url
15
+ @parsed_data[:version] = version
16
+ @parsed_data[:dtd] = dtd
17
+ end
18
+ @parsed_data
14
19
  end
15
20
 
16
21
  def document
17
22
  doc = Ox.load(data)
23
+ @doc_type_string = doc.nodes.detect do |node|
24
+ node.value&.match?(/^cXML /)
25
+ end&.value
18
26
  doc.nodes.detect do |node|
19
27
  node.value&.match?(/^cxml$/i)
20
28
  end || doc
21
29
  end
22
30
 
31
+ def version
32
+ dtd_url&.match(%r{cXML/(.*)/.*\.dtd})&.to_a&.last
33
+ end
34
+
35
+ def dtd
36
+ dtd_url&.match(%r{cXML/.*/(.*)\.dtd})&.to_a&.last
37
+ end
38
+
39
+ def dtd_url
40
+ return nil unless @doc_type_string
41
+
42
+ @doc_type_string.match(/http.*\.dtd/)&.to_a&.first
43
+ end
44
+
23
45
  private
24
46
 
25
47
  def node_to_hash(node) # rubocop:disable Metrics/AbcSize
data/lib/cxml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CXML
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -66,6 +66,20 @@ describe CXML::Document do
66
66
  doc.response.should be_nil
67
67
  doc.message.should be_nil
68
68
  end
69
+
70
+ it 'sets the correct document version' do
71
+ doc.version.should be_a String
72
+ doc.version.should eq '1.2.011'
73
+ end
74
+
75
+ it 'sets the correct document dtd' do
76
+ doc.dtd.should be_a String
77
+ doc.dtd.should eq 'cXML'
78
+ described_class
79
+ .new
80
+ .from_xml(fixture('invoice_backed_and_unbacked_by_pos.xml'))
81
+ .dtd.should eq 'InvoiceDetail'
82
+ end
69
83
  end
70
84
 
71
85
  context 'when a response document is passed' do
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
 
3
- <!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2...oiceDetail.dtd">
3
+ <!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.0.11/InvoiceDetail.dtd">
4
4
 
5
5
  <cXML version="1.0" payloadID="1240598937@SUBDOMAIN.coupahost.com" timestamp="2018-05-04T01:24:51-07:00">
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cxml-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Beckman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-20 00:00:00.000000000 Z
12
+ date: 2020-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ox