Class: Nokogiri::HTML5::Node
- Inherits:
-
Object
- Object
- Nokogiri::HTML5::Node
- Defined in:
- lib/wasmify/rails/shims/nokogiri.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#[](attribute_name) ⇒ Object
Attribute access.
- #[]=(attribute_name, value) ⇒ Object
- #ancestors ⇒ Object
-
#children ⇒ Object
DOM traversal.
-
#initialize(name, attributes = {}) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #key?(attribute_name) ⇒ Boolean
-
#matches?(selector) ⇒ Boolean
CSS matching.
-
#name ⇒ Object
Node type and content.
- #remove_attribute(attribute_name) ⇒ Object
-
#replace(replacement) ⇒ Object
DOM manipulation.
- #text ⇒ Object
- #text? ⇒ Boolean
-
#to_html(options = {}) ⇒ Object
HTML output.
- #to_s ⇒ Object
Constructor Details
#initialize(name, attributes = {}) ⇒ Node
Returns a new instance of Node.
75 76 77 78 79 80 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 75 def initialize(name, attributes = {}) @name = name @attributes = attributes @children = [] @text = "" end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
73 74 75 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 73 def parent @parent end |
Instance Method Details
#[](attribute_name) ⇒ Object
Attribute access
97 98 99 100 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 97 def [](attribute_name) # Get attribute value @attributes[attribute_name] end |
#[]=(attribute_name, value) ⇒ Object
102 103 104 105 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 102 def []=(attribute_name, value) # Set attribute value @attributes[attribute_name] = value end |
#ancestors ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 123 def ancestors # Return array of ancestor nodes (parent, grandparent, etc.) result = [] node = parent while node result << node node = node.parent end result end |
#children ⇒ Object
DOM traversal
118 119 120 121 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 118 def children # Return array of child nodes @children end |
#inspect ⇒ Object
154 155 156 157 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 154 def inspect # For debugging "#<Node:#{name} #{@attributes.inspect}>" end |
#key?(attribute_name) ⇒ Boolean
107 108 109 110 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 107 def key?(attribute_name) # Check if attribute exists @attributes.key?(attribute_name) end |
#matches?(selector) ⇒ Boolean
CSS matching
141 142 143 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 141 def matches?(selector) # Check if this node matches the given CSS selector end |
#name ⇒ Object
Node type and content
83 84 85 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 83 def name @name # e.g., "p", "div", "text", etc. end |
#remove_attribute(attribute_name) ⇒ Object
112 113 114 115 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 112 def remove_attribute(attribute_name) # Remove attribute and return its value @attributes.delete(attribute_name) end |
#replace(replacement) ⇒ Object
DOM manipulation
135 136 137 138 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 135 def replace(replacement) # Replace this node with the replacement (string or node) # If replacement is a string, parse it as HTML end |
#text ⇒ Object
87 88 89 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 87 def text # Return text content (for text nodes) or aggregate text of children end |
#text? ⇒ Boolean
91 92 93 94 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 91 def text? # Return true if this is a text node name == "text" || name == "#text" end |
#to_html(options = {}) ⇒ Object
HTML output
146 147 148 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 146 def to_html( = {}) # Convert to HTML string end |
#to_s ⇒ Object
150 151 152 |
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 150 def to_s to_html end |