Method: Nokogiri::XML::Searchable#at!

Defined in:
lib/ryoba/nokogiri/xml/searchable.rb

#at!(*queries) ⇒ Nokogiri::XML::Element

Like Searchable#at, but raises an error if there are no results.

Examples:

xml = Nokogiri::XML(<<-XML)
  <body>
    <div id="a" />
    <div id="b" />
  </body>
XML

xml.at!("div")  # == Node div#a
xml.at!("img")  # raise error

Parameters:

  • queries (Array<String>)

Returns:

  • (Nokogiri::XML::Element)

Raises:



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