Module: Nokogiri::XML::Searchable
- Defined in:
- lib/ryoba/nokogiri/xml/searchable.rb
Instance Method Summary collapse
-
#ancestor(selector = nil) ⇒ Nokogiri::XML::Element?
Like Searchable#ancestors, but returns only the first matching ancestor.
-
#ancestor!(selector = nil) ⇒ Nokogiri::XML::Element
Like Searchable#ancestors!, but returns only the first matching ancestor.
-
#ancestors!(selector = nil) ⇒ Nokogiri::XML::NodeSet
Like Searchable#ancestors, but raises an error if there are no matching ancestors.
-
#at!(*queries) ⇒ Nokogiri::XML::Element
Like Searchable#at, but raises an error if there are no results.
-
#search!(*queries) ⇒ Nokogiri::XML::NodeSet
Like Searchable#search, but raises an error if there are no results.
Instance Method Details
#ancestor(selector = nil) ⇒ Nokogiri::XML::Element?
Like Searchable#ancestors, but returns only the first matching ancestor.
104 105 106 |
# File 'lib/ryoba/nokogiri/xml/searchable.rb', line 104 def ancestor(selector = nil) self.ancestors(selector).first end |
#ancestor!(selector = nil) ⇒ Nokogiri::XML::Element
Like Searchable#ancestors!, but returns only the first matching ancestor.
130 131 132 |
# File 'lib/ryoba/nokogiri/xml/searchable.rb', line 130 def ancestor!(selector = nil) self.ancestors!(selector).first end |
#ancestors!(selector = nil) ⇒ Nokogiri::XML::NodeSet
Like Searchable#ancestors, but raises an error if there are no matching ancestors.
76 77 78 79 80 81 82 |
# File 'lib/ryoba/nokogiri/xml/searchable.rb', line 76 def ancestors!(selector = nil) results = self.ancestors(selector) if results.empty? raise Ryoba::Error.new("No ancestors matching #{selector.inspect}") end results end |
#at!(*queries) ⇒ Nokogiri::XML::Element
Like Searchable#at, but raises an error if there are no results.
46 47 48 49 50 51 52 |
# File 'lib/ryoba/nokogiri/xml/searchable.rb', line 46 def at!(*queries) result = self.at(*queries) if result.nil? raise Ryoba::Error.new("No elements matching #{queries.map(&:inspect).join(" OR ")}") end result end |
#search!(*queries) ⇒ Nokogiri::XML::NodeSet
Like Searchable#search, but raises an error if there are no results.
21 22 23 24 25 26 27 |
# File 'lib/ryoba/nokogiri/xml/searchable.rb', line 21 def search!(*queries) results = self.search(*queries) if results.empty? raise Ryoba::Error.new("No elements matching #{queries.map(&:inspect).join(" OR ")}") end results end |