Class: Escapement::Tag
- Inherits:
-
Object
- Object
- Escapement::Tag
- Includes:
- PrettyNames, Traversal
- Defined in:
- lib/escapement/tag.rb
Overview
A tag represents an entity that may or may not have child elements. Once we extract the data about this DOM node, we recursively continue the traversal until we reach the leaf text node.
Instance Attribute Summary collapse
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(node, start_position) ⇒ Tag
constructor
A new instance of Tag.
- #process ⇒ Object
Methods included from PrettyNames
Methods included from Traversal
Constructor Details
#initialize(node, start_position) ⇒ Tag
Returns a new instance of Tag.
11 12 13 14 15 |
# File 'lib/escapement/tag.rb', line 11 def initialize(node, start_position) @node = node @start_position = @current_position = start_position @entities = [] end |
Instance Attribute Details
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
9 10 11 |
# File 'lib/escapement/tag.rb', line 9 def entities @entities end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
9 10 11 |
# File 'lib/escapement/tag.rb', line 9 def node @node end |
Instance Method Details
#process ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/escapement/tag.rb', line 17 def process @entities << { type: node_to_type, html_tag: node.name, position: [@current_position, @current_position + node.text.length], attributes: Hash[filtered_attributes.map { |k, v| [k, v.value] }] } process_children end |