Module: Nokogiri::XML::Searchable
- Defined in:
- lib/ryoba/nokogiri/xml/searchable.rb
Instance Method Summary collapse
-
#ancestor(selector = nil) ⇒ Nokogiri::XML::Element?
Like
#ancestors, but returns only the first matching ancestor. -
#ancestor!(selector = nil) ⇒ Nokogiri::XML::Element
Like #ancestors!, but returns only the first matching ancestor.
-
#ancestors!(selector = nil) ⇒ Nokogiri::XML::NodeSet
Like
#ancestors, but raises an exception if there are no matching ancestors. -
#at!(*queries) ⇒ Nokogiri::XML::Element
Like
#at, but raises an exception if there are no results. -
#search!(*queries) ⇒ Nokogiri::XML::NodeSet
Like
#search, but raises an exception if there are no results.
Instance Method Details
#ancestor(selector = nil) ⇒ Nokogiri::XML::Element?
Like #ancestors, but returns only the first matching ancestor.
103 104 105 |
# File 'lib/ryoba/nokogiri/xml/searchable.rb', line 103 def ancestor(selector = nil) self.ancestors(selector).first end |
#ancestor!(selector = nil) ⇒ Nokogiri::XML::Element
Like #ancestors!, but returns only the first matching ancestor.
128 129 130 |
# File 'lib/ryoba/nokogiri/xml/searchable.rb', line 128 def ancestor!(selector = nil) self.ancestors!(selector).first end |
#ancestors!(selector = nil) ⇒ Nokogiri::XML::NodeSet
Like #ancestors, but raises an exception 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 #at, but raises an exception if there are no results.
45 46 47 48 49 50 51 |
# File 'lib/ryoba/nokogiri/xml/searchable.rb', line 45 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 #search, but raises an exception if there are no results.
20 21 22 23 24 25 26 |
# File 'lib/ryoba/nokogiri/xml/searchable.rb', line 20 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 |