Class: Scrapetor::CommentNode

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#documentObject (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_nodesObject



47
# File 'lib/scrapetor/comment_node.rb', line 47

def attribute_nodes; []; end

#attributesObject

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

Returns:

  • (Boolean)


39
# File 'lib/scrapetor/comment_node.rb', line 39

def cdata?;      false; end

#childrenObject



51
# File 'lib/scrapetor/comment_node.rb', line 51

def children;    [];    end

#classesObject



53
# File 'lib/scrapetor/comment_node.rb', line 53

def classes;     [];    end

#comment?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


38
# File 'lib/scrapetor/comment_node.rb', line 38

def document?;   false; end

#element?Boolean

Returns:

  • (Boolean)


36
# File 'lib/scrapetor/comment_node.rb', line 36

def element?;    false; end

#element_childrenObject



52
# File 'lib/scrapetor/comment_node.rb', line 52

def element_children; []; end

#has_class?(_) ⇒ Boolean

Returns:

  • (Boolean)


54
# File 'lib/scrapetor/comment_node.rb', line 54

def has_class?(_); false; end

#inspectObject



63
64
65
# File 'lib/scrapetor/comment_node.rb', line 63

def inspect
  "#<Scrapetor::CommentNode #{@text.inspect}>"
end

#keysObject



49
# File 'lib/scrapetor/comment_node.rb', line 49

def keys;        [];    end

#nameObject Also known as: node_name



32
# File 'lib/scrapetor/comment_node.rb', line 32

def name;        "#comment"; end

#node_typeObject



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

#textObject Also known as: content, inner_text



23
# File 'lib/scrapetor/comment_node.rb', line 23

def text;        @text; end

#text?Boolean

Returns:

  • (Boolean)


37
# File 'lib/scrapetor/comment_node.rb', line 37

def text?;       false; end

#to_htmlObject Also known as: outer_html, inner_html



28
# File 'lib/scrapetor/comment_node.rb', line 28

def to_html;     "<!--#{@text}-->"; end

#to_sObject



27
# File 'lib/scrapetor/comment_node.rb', line 27

def to_s;        @text; end

#valuesObject



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