Class: CXML::Parser
- Inherits:
-
Object
- Object
- CXML::Parser
- Defined in:
- lib/cxml/parser.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#parsed_data ⇒ Object
Returns the value of attribute parsed_data.
Instance Method Summary collapse
- #document ⇒ Object
- #dtd ⇒ Object
- #dtd_url ⇒ Object
-
#initialize(data:) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(data:) ⇒ Parser
Returns a new instance of Parser.
8 9 10 |
# File 'lib/cxml/parser.rb', line 8 def initialize(data:) @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/cxml/parser.rb', line 5 def data @data end |
#parsed_data ⇒ Object
Returns the value of attribute parsed_data.
5 6 7 |
# File 'lib/cxml/parser.rb', line 5 def parsed_data @parsed_data end |
Instance Method Details
#document ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/cxml/parser.rb', line 21 def document doc = Ox.load(data) @doc_type_string = doc.nodes.detect do |node| node.value&.match?(/^cXML /) end&.value doc.nodes.detect do |node| node.value&.match?(/^cxml$/i) end || doc end |
#dtd ⇒ Object
35 36 37 |
# File 'lib/cxml/parser.rb', line 35 def dtd dtd_url&.match(%r{cXML/.*/(.*)\.dtd})&.to_a&.last end |
#dtd_url ⇒ Object
39 40 41 42 43 |
# File 'lib/cxml/parser.rb', line 39 def dtd_url return nil unless @doc_type_string @doc_type_string.match(/http.*\.dtd/)&.to_a&.first end |
#parse ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/cxml/parser.rb', line 12 def parse @parsed_data = node_to_hash document if dtd_url @parsed_data[:version] = version @parsed_data[:dtd] = dtd end @parsed_data end |
#version ⇒ Object
31 32 33 |
# File 'lib/cxml/parser.rb', line 31 def version dtd_url&.match(%r{cXML/(.*)/.*\.dtd})&.to_a&.last end |