Method: Nokogiri::XML::Node#content?

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

#content?String? Also known as: inner_text?

Equivalent to .content.strip, but returns nil if the result is an empty string.

Examples:

xml = Nokogiri::XML(<<-XML)
  <body>
    <h1>
      Headline 1
    </h1>
    <h2> Headline 2 </h2>
    <h3> </h3>
  </body>
XML

xml.at("h1").content?  # == "Headline 1"
xml.at("h2").content?  # == "Headline 2"
xml.at("h3").content?  # == nil

Returns:

  • (String, nil)


24
25
26
27
# File 'lib/ryoba/nokogiri/xml/node.rb', line 24

def content?
  result = self.content.strip
  result unless result.empty?
end