Class: Nokogiri::HTML5::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/wasmify/rails/shims/nokogiri.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#parentObject

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

#ancestorsObject



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

#childrenObject

DOM traversal



118
119
120
121
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 118

def children
  # Return array of child nodes
  @children
end

#inspectObject



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

Returns:

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

Returns:

  • (Boolean)


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

#nameObject

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

#textObject



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

Returns:

  • (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(options = {})
  # Convert to HTML string
end

#to_sObject



150
151
152
# File 'lib/wasmify/rails/shims/nokogiri.rb', line 150

def to_s
  to_html
end