Class: SvgConform::ElementProxy
- Inherits:
-
Object
- Object
- SvgConform::ElementProxy
- Defined in:
- lib/svg_conform/element_proxy.rb
Overview
Lightweight element representation during SAX parsing Provides a node-like interface for validation requirements without the overhead of full DOM tree
Instance Attribute Summary collapse
-
#child_counters ⇒ Object
Returns the value of attribute child_counters.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#raw_attributes ⇒ Object
readonly
Returns the value of attribute raw_attributes.
-
#text_content ⇒ Object
Returns the value of attribute text_content.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Get attribute value (alias for compatibility).
-
#attribute(name) ⇒ Object
Check if this element has a specific attribute.
-
#attributes ⇒ Object
Return attributes as array of SaxAttribute objects (for compatibility).
- #column ⇒ Object
-
#element_id ⇒ Object
Provide a stable identifier for this element.
-
#has_attribute?(name) ⇒ Boolean
Check if attribute exists.
-
#initialize(name:, attributes:, position:, path:, parent:) ⇒ ElementProxy
constructor
A new instance of ElementProxy.
-
#line ⇒ Object
For compatibility with validation context.
-
#method_missing(method, *_args) ⇒ Object
Support dynamic attribute access.
-
#namespace ⇒ Object
Get namespace from attributes or parent.
-
#path_id ⇒ Object
Build full path ID for this element.
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
-
#text? ⇒ Boolean
Check if this is a text node (always false for ElementProxy).
Constructor Details
#initialize(name:, attributes:, position:, path:, parent:) ⇒ ElementProxy
Returns a new instance of ElementProxy.
25 26 27 28 29 30 31 32 33 |
# File 'lib/svg_conform/element_proxy.rb', line 25 def initialize(name:, attributes:, position:, path:, parent:) @name = name @raw_attributes = attributes # Hash of attribute name => value @position = position @path = path # Array of parent path parts @parent = parent @text_content = +"" # Mutable string @child_counters = {} # Track child element positions end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *_args) ⇒ Object
Support dynamic attribute access
73 74 75 76 77 78 79 80 81 |
# File 'lib/svg_conform/element_proxy.rb', line 73 def method_missing(method, *_args) if method.to_s.end_with?("?") # Boolean check has_attribute?(method.to_s.chomp("?")) else # Attribute access @attributes[method.to_s] || @attributes[method.to_sym] end end |
Instance Attribute Details
#child_counters ⇒ Object
Returns the value of attribute child_counters.
23 24 25 |
# File 'lib/svg_conform/element_proxy.rb', line 23 def child_counters @child_counters end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/svg_conform/element_proxy.rb', line 22 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
22 23 24 |
# File 'lib/svg_conform/element_proxy.rb', line 22 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
22 23 24 |
# File 'lib/svg_conform/element_proxy.rb', line 22 def path @path end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
22 23 24 |
# File 'lib/svg_conform/element_proxy.rb', line 22 def position @position end |
#raw_attributes ⇒ Object (readonly)
Returns the value of attribute raw_attributes.
22 23 24 |
# File 'lib/svg_conform/element_proxy.rb', line 22 def raw_attributes @raw_attributes end |
#text_content ⇒ Object
Returns the value of attribute text_content.
23 24 25 |
# File 'lib/svg_conform/element_proxy.rb', line 23 def text_content @text_content end |
Instance Method Details
#[](name) ⇒ Object
Get attribute value (alias for compatibility)
53 54 55 |
# File 'lib/svg_conform/element_proxy.rb', line 53 def [](name) @raw_attributes[name] || @raw_attributes[name.to_s] end |
#attribute(name) ⇒ Object
Check if this element has a specific attribute
47 48 49 50 |
# File 'lib/svg_conform/element_proxy.rb', line 47 def attribute(name) value = @raw_attributes[name] || @raw_attributes[name.to_s] value ? SaxAttribute.new(name, value) : nil end |
#attributes ⇒ Object
Return attributes as array of SaxAttribute objects (for compatibility)
42 43 44 |
# File 'lib/svg_conform/element_proxy.rb', line 42 def attributes @raw_attributes.map { |name, value| SaxAttribute.new(name, value) } end |
#column ⇒ Object
92 93 94 |
# File 'lib/svg_conform/element_proxy.rb', line 92 def column nil end |
#element_id ⇒ Object
Provide a stable identifier for this element
97 98 99 |
# File 'lib/svg_conform/element_proxy.rb', line 97 def element_id path_id end |
#has_attribute?(name) ⇒ Boolean
Check if attribute exists
58 59 60 |
# File 'lib/svg_conform/element_proxy.rb', line 58 def has_attribute?(name) @raw_attributes.key?(name) || @raw_attributes.key?(name.to_s) end |
#line ⇒ Object
For compatibility with validation context
88 89 90 |
# File 'lib/svg_conform/element_proxy.rb', line 88 def line nil # SAX doesn't provide line numbers easily end |
#namespace ⇒ Object
Get namespace from attributes or parent
63 64 65 |
# File 'lib/svg_conform/element_proxy.rb', line 63 def namespace @raw_attributes["xmlns"] || @parent&.namespace end |
#path_id ⇒ Object
Build full path ID for this element
36 37 38 39 |
# File 'lib/svg_conform/element_proxy.rb', line 36 def path_id parts = @path + ["#{@name}[#{@position}]"] "/#{parts.join('/')}" end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
83 84 85 |
# File 'lib/svg_conform/element_proxy.rb', line 83 def respond_to_missing?(method, include_private = false) @raw_attributes.key?(method.to_s) || @raw_attributes.key?(method.to_sym) || super end |
#text? ⇒ Boolean
Check if this is a text node (always false for ElementProxy)
68 69 70 |
# File 'lib/svg_conform/element_proxy.rb', line 68 def text? false end |