Class: Sawzall::Element
- Inherits:
-
Object
- Object
- Sawzall::Element
- Defined in:
- lib/sawzall.rb
1) Querying collapse
-
#attr(attribute) ⇒ String, Nil
Returns the given attribute’s value or
nil
. -
#attrs ⇒ Array<Array(String, String)>
Returns the element’s attributes as an array of key-value pairs.
-
#child_elements ⇒ Array<Sawzall::Element>
Returns the element’s child elements.
-
#classes ⇒ Array<String>
Returns the element’s classes.
-
#has_class?(css_class, case_sensitive: true) ⇒ Boolean
Checks whether the element has the given class.
-
#html ⇒ String
Returns the element’s outer HTML.
-
#inner_html ⇒ String
Returns the element’s inner HTML.
-
#name ⇒ String
Returns the element’s name in lowercase.
-
#select(css_selector) ⇒ Array<Sawzall::Element>
Returns the child elements that match the given CSS selector.
-
#text ⇒ String
Returns the element’s text content using a very simplified version of the
innerText
algorithm.
2) Debugging collapse
-
#inspect ⇒ Object
Overrides Ruby’s default
Object#inspect
so the output is a bit more useful. -
#pretty_print(pp) ⇒ Object
Provides a custom pretty-printing implementation for Ruby’s
PP
.
Instance Method Details
#attr(attribute) ⇒ String, Nil
Returns the given attribute’s value or nil
|
# File 'lib/sawzall.rb', line 116
|
#attrs ⇒ Array<Array(String, String)>
Returns the element’s attributes as an array of key-value pairs
|
# File 'lib/sawzall.rb', line 128
|
#child_elements ⇒ Array<Sawzall::Element>
Returns the element’s child elements
|
# File 'lib/sawzall.rb', line 158
|
#classes ⇒ Array<String>
Returns the element’s classes
|
# File 'lib/sawzall.rb', line 210
|
#has_class?(css_class, case_sensitive: true) ⇒ Boolean
Checks whether the element has the given class
|
# File 'lib/sawzall.rb', line 195
|
#html ⇒ String
Returns the element’s outer HTML
|
# File 'lib/sawzall.rb', line 88
|
#inner_html ⇒ String
Returns the element’s inner HTML
|
# File 'lib/sawzall.rb', line 102
|
#inspect ⇒ Object
Overrides Ruby’s default Object#inspect
so the output is a bit more useful
225 226 227 |
# File 'lib/sawzall.rb', line 225 def inspect "<#{self.class.name} name=#{name.inspect} child_elements=#{child_elements.inspect}>" end |
#name ⇒ String
Returns the element’s name in lowercase
|
# File 'lib/sawzall.rb', line 79
|
#pretty_print(pp) ⇒ Object
Provides a custom pretty-printing implementation for Ruby’s PP
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/sawzall.rb', line 230 def pretty_print(pp) pp.group(2, "#(#{self.class.name} {", "})") do pp.breakable fields = [:name] fields << :child_elements unless child_elements.empty? pp.seplist(fields) do |field| case field when :name pp.text("name = ") pp.pp(name) when :child_elements pp.group(2, "child_elements = [", "]") do pp.breakable pp.seplist(child_elements) do |child| pp.pp(child) end end end end pp.breakable end end |
#select(css_selector) ⇒ Array<Sawzall::Element>
Returns the child elements that match the given CSS selector
|
# File 'lib/sawzall.rb', line 138
|
#text ⇒ String
Returns the element’s text content using a very simplified version of the innerText
algorithm.
developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
|
# File 'lib/sawzall.rb', line 177
|