Class: HTML::Text
- Defined in:
- lib/action_controller/vendor/html-scanner/html/node.rb
Overview
A node that represents text, rather than markup.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
:nodoc:.
Attributes inherited from Node
#children, #line, #parent, #position
Instance Method Summary collapse
-
#find(conditions) ⇒ Object
Returns
self
if this node meets the given conditions. -
#initialize(parent, line, pos, content) ⇒ Text
constructor
Creates a new text node as a child of the given parent, with the given content.
-
#match(conditions) ⇒ Object
Returns non-
nil
if this node meets the given conditions, ornil
otherwise. -
#to_s ⇒ Object
Returns the content of this node.
Methods inherited from Node
#find_all, parse, #tag?, #validate_conditions
Constructor Details
#initialize(parent, line, pos, content) ⇒ Text
Creates a new text node as a child of the given parent, with the given content.
196 197 198 199 |
# File 'lib/action_controller/vendor/html-scanner/html/node.rb', line 196 def initialize(parent, line, pos, content) super(parent, line, pos) @content = content end |
Instance Attribute Details
#content ⇒ Object (readonly)
:nodoc:
192 193 194 |
# File 'lib/action_controller/vendor/html-scanner/html/node.rb', line 192 def content @content end |
Instance Method Details
#find(conditions) ⇒ Object
Returns self
if this node meets the given conditions. Text nodes support conditions of the following kinds:
-
if
conditions
is a string, it must be a substring of the node’s content -
if
conditions
is a regular expression, it must match the node’s content -
if
conditions
is a hash, it must contain a:content
key that is either a string or a regexp, and which is interpreted as described above.
216 217 218 |
# File 'lib/action_controller/vendor/html-scanner/html/node.rb', line 216 def find(conditions) match(conditions) && self end |
#match(conditions) ⇒ Object
Returns non-nil
if this node meets the given conditions, or nil
otherwise. See the discussion of #find for the valid conditions.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/action_controller/vendor/html-scanner/html/node.rb', line 222 def match(conditions) case conditions when String @content.index(conditions) when Regexp @content =~ conditions when Hash conditions = validate_conditions(conditions) # Text nodes only have :content, :parent, :ancestor unless (conditions.keys - [:content, :parent, :ancestor]).empty? return false end match(conditions[:content]) else nil end end |
#to_s ⇒ Object
Returns the content of this node.
202 203 204 |
# File 'lib/action_controller/vendor/html-scanner/html/node.rb', line 202 def to_s @content end |