Class: HTML::Text

Inherits:
Node show all
Defined in:
actionpack/lib/action_controller/vendor/html-scanner/html/node.rb

Overview

A node that represents text, rather than markup.

Instance Attribute Summary (collapse)

Attributes inherited from Node

#children, #line, #parent, #position

Instance Method Summary (collapse)

Methods inherited from Node

#find_all, parse, #tag?, #validate_conditions

Constructor Details

- (Text) initialize(parent, line, pos, content)

Creates a new text node as a child of the given parent, with the given content.



214
215
216
217
# File 'actionpack/lib/action_controller/vendor/html-scanner/html/node.rb', line 214

def initialize(parent, line, pos, content)
  super(parent, line, pos)
  @content = content
end

Instance Attribute Details

- (Object) content (readonly)

:nodoc:



210
211
212
# File 'actionpack/lib/action_controller/vendor/html-scanner/html/node.rb', line 210

def content
  @content
end

Instance Method Details

- (Object) ==(node)



260
261
262
263
# File 'actionpack/lib/action_controller/vendor/html-scanner/html/node.rb', line 260

def ==(node)
  return false unless super
  content == node.content
end

- (Object) find(conditions)

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.



234
235
236
# File 'actionpack/lib/action_controller/vendor/html-scanner/html/node.rb', line 234

def find(conditions)
  match(conditions) && self
end

- (Object) match(conditions)

Returns non-nil if this node meets the given conditions, or nil otherwise. See the discussion of #find for the valid conditions.



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'actionpack/lib/action_controller/vendor/html-scanner/html/node.rb', line 240

def match(conditions)
  case conditions
    when String
      @content == 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

- (Object) to_s

Returns the content of this node.



220
221
222
# File 'actionpack/lib/action_controller/vendor/html-scanner/html/node.rb', line 220

def to_s
  @content
end