Class: Sawzall::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/sawzall.rb

Instance Method Summary collapse

Instance Method Details

#root_elementSawzall::Element

Returns the document’s root element

Examples:

doc = Sawzall.parse_fragment("<h1>Heading</h1>")
doc.root_element.name #=> "html"
doc.root_element.child_elements.map(&:name) #=> ["h1"]

Returns:



# File 'lib/sawzall.rb', line 20

#select(css_selector) ⇒ Array<Sawzall::Element>

Returns the elements that match the given CSS selector

Examples:

doc = Sawzall.parse_fragment(<<~HTML)
  <h1>Heading</h1>
  <p>Paragraph 1</p>
  <p>Paragraph 2</p>
HTML
matches = doc.select("p")
matches.map(&:text) #=> ["Paragraph 1", "Paragraph 2"]

Parameters:

  • css_selector (String)

Returns:

Raises:

  • (ArgumentError)

    if the CSS selector is invalid



# File 'lib/sawzall.rb', line 2