Class: CodeModels::Xml::Parser
- Inherits:
-
Parser
- Object
- Parser
- CodeModels::Xml::Parser
- Defined in:
- lib/codemodels/xml/parser.rb
Instance Method Summary collapse
- #build_attribute(raw_node) ⇒ Object
- #build_document(raw_node) ⇒ Object
- #build_element(raw_node) ⇒ Object
- #build_text(raw_node) ⇒ Object
- #convert_raw_ast(raw_node) ⇒ Object
- #internal_parse_artifact(artifact) ⇒ Object
Instance Method Details
#build_attribute(raw_node) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/codemodels/xml/parser.rb', line 28 def build_attribute(raw_node) node = Attribute.new node.name = raw_node.name node.value = raw_node.value node end |
#build_document(raw_node) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/codemodels/xml/parser.rb', line 58 def build_document(raw_node) node = Document.new node.version = raw_node.version node.encoding = raw_node.encoding for n in raw_node.namespaces node.addNamespaces(convert_raw_ast(n)) end node.root = convert_raw_ast(raw_node.root) node end |
#build_element(raw_node) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/codemodels/xml/parser.rb', line 40 def build_element(raw_node) node = Element.new node.name = raw_node.name raw_node.attribute_nodes.each do |c| node.addAttributes(convert_raw_ast(c)) end raw_node.children.each do |c| if c.is_a?(Nokogiri::XML::Text) node.addTexts(convert_raw_ast(c)) elsif c.is_a?(Nokogiri::XML::Element) node.addChildren(convert_raw_ast(c)) else raise "Unexpected child type: #{c.class}" end end node end |
#build_text(raw_node) ⇒ Object
35 36 37 38 |
# File 'lib/codemodels/xml/parser.rb', line 35 def build_text(raw_node) node = Text.new node end |
#convert_raw_ast(raw_node) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/codemodels/xml/parser.rb', line 14 def convert_raw_ast(raw_node) if raw_node.is_a?(Nokogiri::XML::Document) build_document(raw_node) elsif raw_node.is_a?(Nokogiri::XML::Element) build_element(raw_node) elsif raw_node.is_a?(Nokogiri::XML::Text) build_text(raw_node) elsif raw_node.is_a?(Nokogiri::XML::Attr) build_attribute(raw_node) else raise "Unknown node type #{raw_node.class}" end end |
#internal_parse_artifact(artifact) ⇒ Object
9 10 11 12 |
# File 'lib/codemodels/xml/parser.rb', line 9 def internal_parse_artifact(artifact) raw_ast = Nokogiri.XML(artifact.code) convert_raw_ast(raw_ast) end |