Module: Taurus::XML::Searchable
Instance Method Summary collapse
- #at(*args) ⇒ Object (also: #%)
- #at_css(*args) ⇒ Object
- #at_xpath(*paths) ⇒ Object
- #css(*args) ⇒ Object
- #search(*args) ⇒ Object (also: #/)
- #xpath(*paths) ⇒ Object
Instance Method Details
#at(*args) ⇒ Object Also known as: %
32 33 34 35 |
# File 'lib/taurus/xml/searchable.rb', line 32 def at(*args) result = search(*args) result.is_a?(Taurus::XML::NodeSet) ? result.first : result end |
#at_css(*args) ⇒ Object
46 47 48 49 |
# File 'lib/taurus/xml/searchable.rb', line 46 def at_css(*args) result = css(*args) result.is_a?(Taurus::XML::NodeSet) ? result.first : result end |
#at_xpath(*paths) ⇒ Object
21 22 23 24 |
# File 'lib/taurus/xml/searchable.rb', line 21 def at_xpath(*paths) result = xpath(*paths) result.is_a?(Taurus::XML::NodeSet) ? result.first : result end |
#css(*args) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/taurus/xml/searchable.rb', line 38 def css(*args) handler, ns, _ = parse_search_args(args) raise ArgumentError, "namespace bindings not supported in css" if ns && !ns.empty? raise ArgumentError, "custom CSS handlers not supported" if handler expr = args.map { |r| Taurus::XML::CssToXPath.convert(r) }.join(" | ") xpath(expr) end |
#search(*args) ⇒ Object Also known as: /
26 27 28 29 |
# File 'lib/taurus/xml/searchable.rb', line 26 def search(*args) paths = args.first.is_a?(Array) ? args.first : [args.first] paths.map(&:to_s).all? { |p| looks_like_xpath?(p) } ? xpath(*paths) : css(*paths) end |
#xpath(*paths) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/taurus/xml/searchable.rb', line 4 def xpath(*paths) handler, _ns, _vars = parse_search_args(paths) raise ArgumentError, "custom XPath handlers not supported" if handler expr = paths.join(" | ") doc_ptr = is_a?(Taurus::XML::Document) ? c_ptr : document.c_ptr context_ptr = is_a?(Taurus::XML::Document) ? nil : c_ptr result_ptr = Taurus::XML::FFI.taurus_xpath_eval(doc_ptr, context_ptr, expr) if result_ptr.null? raise Taurus::XML::XPathError, Taurus::XML::FFI.taurus_status_string(Taurus::XML::FFI::TAURUS_ERROR_XPATH) end wrap_xpath_result(result_ptr) end |