Class: Scrapetor::CommentNode
- Inherits:
-
Object
- Object
- Scrapetor::CommentNode
- Defined in:
- lib/scrapetor/comment_node.rb
Overview
Result type for XPath ‘comment()` queries (`//comment()`, `child::comment()`, etc.). Carries the comment’s text payload and implements the Node-shape predicate methods so duck-typing checks (‘n.comment?`, `n.element?`, `n.name == “#comment”`) match what Nokogiri would return.
The constructor accepts a String (extracted by the native engine’s ‘node_comment_text`) or a Dom::Comment (Ruby fallback path); in either case `#text` / `#content` returns the payload between `<!–` and `–>`.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
- #[](*_args) ⇒ Object
- #at(_) ⇒ Object
- #at_css(_) ⇒ Object
- #at_xpath(*_) ⇒ Object
- #attribute(_) ⇒ Object
- #attribute_nodes ⇒ Object
-
#attributes ⇒ Object
Node-shape probes that scraping code occasionally fires against mixed result sets.
- #cdata? ⇒ Boolean
- #children ⇒ Object
- #classes ⇒ Object
- #comment? ⇒ Boolean
- #css(_) ⇒ Object
- #document? ⇒ Boolean
- #element? ⇒ Boolean
- #element_children ⇒ Object
- #has_class?(_) ⇒ Boolean
-
#initialize(document, payload) ⇒ CommentNode
constructor
A new instance of CommentNode.
- #inspect ⇒ Object
- #keys ⇒ Object
- #name ⇒ Object (also: #node_name)
- #node_type ⇒ Object
- #search(_) ⇒ Object
- #text ⇒ Object (also: #content, #inner_text)
- #text? ⇒ Boolean
- #to_html ⇒ Object (also: #outer_html, #inner_html)
- #to_s ⇒ Object
- #values ⇒ Object
- #xpath(*_) ⇒ Object
Constructor Details
#initialize(document, payload) ⇒ CommentNode
Returns a new instance of CommentNode.
17 18 19 20 21 |
# File 'lib/scrapetor/comment_node.rb', line 17 def initialize(document, payload) @document = document @text = payload.is_a?(String) ? payload : (payload.respond_to?(:content) ? payload.content.to_s : payload.to_s) end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
15 16 17 |
# File 'lib/scrapetor/comment_node.rb', line 15 def document @document end |
Instance Method Details
#[](*_args) ⇒ Object
55 |
# File 'lib/scrapetor/comment_node.rb', line 55 def [](*_args); nil; end |
#at(_) ⇒ Object
58 |
# File 'lib/scrapetor/comment_node.rb', line 58 def at(_); nil; end |
#at_css(_) ⇒ Object
57 |
# File 'lib/scrapetor/comment_node.rb', line 57 def at_css(_); nil; end |
#at_xpath(*_) ⇒ Object
61 |
# File 'lib/scrapetor/comment_node.rb', line 61 def at_xpath(*_); nil; end |
#attribute(_) ⇒ Object
48 |
# File 'lib/scrapetor/comment_node.rb', line 48 def attribute(_); nil; end |
#attribute_nodes ⇒ Object
47 |
# File 'lib/scrapetor/comment_node.rb', line 47 def attribute_nodes; []; end |
#attributes ⇒ Object
Node-shape probes that scraping code occasionally fires against mixed result sets. Returning a benign default keeps a stray ‘.css(…)` or `.attributes` from raising NoMethodError when a caller iterates over an Array<Element + CommentNode>.
46 |
# File 'lib/scrapetor/comment_node.rb', line 46 def attributes; {}; end |
#cdata? ⇒ Boolean
39 |
# File 'lib/scrapetor/comment_node.rb', line 39 def cdata?; false; end |
#children ⇒ Object
51 |
# File 'lib/scrapetor/comment_node.rb', line 51 def children; []; end |
#classes ⇒ Object
53 |
# File 'lib/scrapetor/comment_node.rb', line 53 def classes; []; end |
#comment? ⇒ Boolean
35 |
# File 'lib/scrapetor/comment_node.rb', line 35 def comment?; true; end |
#css(_) ⇒ Object
56 |
# File 'lib/scrapetor/comment_node.rb', line 56 def css(_); []; end |
#document? ⇒ Boolean
38 |
# File 'lib/scrapetor/comment_node.rb', line 38 def document?; false; end |
#element? ⇒ Boolean
36 |
# File 'lib/scrapetor/comment_node.rb', line 36 def element?; false; end |
#element_children ⇒ Object
52 |
# File 'lib/scrapetor/comment_node.rb', line 52 def element_children; []; end |
#has_class?(_) ⇒ Boolean
54 |
# File 'lib/scrapetor/comment_node.rb', line 54 def has_class?(_); false; end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/scrapetor/comment_node.rb', line 63 def inspect "#<Scrapetor::CommentNode #{@text.inspect}>" end |
#keys ⇒ Object
49 |
# File 'lib/scrapetor/comment_node.rb', line 49 def keys; []; end |
#name ⇒ Object Also known as: node_name
32 |
# File 'lib/scrapetor/comment_node.rb', line 32 def name; "#comment"; end |
#node_type ⇒ Object
40 |
# File 'lib/scrapetor/comment_node.rb', line 40 def node_type; 8; end |
#search(_) ⇒ Object
59 |
# File 'lib/scrapetor/comment_node.rb', line 59 def search(_); []; end |
#text ⇒ Object Also known as: content, inner_text
23 |
# File 'lib/scrapetor/comment_node.rb', line 23 def text; @text; end |
#text? ⇒ Boolean
37 |
# File 'lib/scrapetor/comment_node.rb', line 37 def text?; false; end |
#to_html ⇒ Object Also known as: outer_html, inner_html
28 |
# File 'lib/scrapetor/comment_node.rb', line 28 def to_html; "<!--#{@text}-->"; end |
#to_s ⇒ Object
27 |
# File 'lib/scrapetor/comment_node.rb', line 27 def to_s; @text; end |
#values ⇒ Object
50 |
# File 'lib/scrapetor/comment_node.rb', line 50 def values; []; end |
#xpath(*_) ⇒ Object
60 |
# File 'lib/scrapetor/comment_node.rb', line 60 def xpath(*_); []; end |