Module: T2Server::XML::Methods
- Included in:
- Administrator, OutputPort, Port, Run, Server, XPathCache
- Defined in:
- lib/t2-server/xml/methods.rb
Instance Method Summary collapse
-
#get_uris_from_doc(doc, keys) ⇒ Object
Given a list of xpath keys, extract the href URIs from those elements.
- #xml_children(doc, &block) ⇒ Object
- #xml_document(string) ⇒ Object
- #xml_first_child(node) ⇒ Object
- #xml_node_attribute(node, attribute) ⇒ Object
- #xml_node_content(node) ⇒ Object
- #xml_node_name(node) ⇒ Object
- #xml_text_node(text) ⇒ Object
- #xpath_attr(doc, expr, attribute) ⇒ Object
- #xpath_compile(xpath) ⇒ Object
- #xpath_find(doc, expr) ⇒ Object
- #xpath_first(doc, expr) ⇒ Object
Instance Method Details
#get_uris_from_doc(doc, keys) ⇒ Object
Given a list of xpath keys, extract the href URIs from those elements.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/t2-server/xml/methods.rb', line 87 def get_uris_from_doc(doc, keys) cache = XPathCache.instance uris = {} keys.each do |key| uri = xpath_attr(doc, cache[key], "href") uris[key] = uri.nil? ? nil : URI.parse(uri) end uris end |
#xml_children(doc, &block) ⇒ Object
53 54 55 |
# File 'lib/t2-server/xml/methods.rb', line 53 def xml_children(doc, &block) doc.each { |node| yield node } end |
#xml_document(string) ⇒ Object
41 42 43 |
# File 'lib/t2-server/xml/methods.rb', line 41 def xml_document(string) LibXML::XML::Document.string(string) end |
#xml_first_child(node) ⇒ Object
49 50 51 |
# File 'lib/t2-server/xml/methods.rb', line 49 def xml_first_child(node) node.first end |
#xml_node_attribute(node, attribute) ⇒ Object
65 66 67 |
# File 'lib/t2-server/xml/methods.rb', line 65 def xml_node_attribute(node, attribute) node.attributes[attribute] end |
#xml_node_content(node) ⇒ Object
61 62 63 |
# File 'lib/t2-server/xml/methods.rb', line 61 def xml_node_content(node) node.content end |
#xml_node_name(node) ⇒ Object
57 58 59 |
# File 'lib/t2-server/xml/methods.rb', line 57 def xml_node_name(node) node.name end |
#xml_text_node(text) ⇒ Object
45 46 47 |
# File 'lib/t2-server/xml/methods.rb', line 45 def xml_text_node(text) LibXML::XML::Node.new_text(text) end |
#xpath_attr(doc, expr, attribute) ⇒ Object
81 82 83 84 |
# File 'lib/t2-server/xml/methods.rb', line 81 def xpath_attr(doc, expr, attribute) node = xpath_first(doc, expr) node.nil? ? nil : node.attributes[attribute] end |
#xpath_compile(xpath) ⇒ Object
69 70 71 |
# File 'lib/t2-server/xml/methods.rb', line 69 def xpath_compile(xpath) LibXML::XML::XPath::Expression.new(xpath) end |
#xpath_find(doc, expr) ⇒ Object
73 74 75 |
# File 'lib/t2-server/xml/methods.rb', line 73 def xpath_find(doc, expr) doc.find(expr, Namespaces::MAP) end |
#xpath_first(doc, expr) ⇒ Object
77 78 79 |
# File 'lib/t2-server/xml/methods.rb', line 77 def xpath_first(doc, expr) doc.find_first(expr, Namespaces::MAP) end |