Class: SvgConform::ElementProxy

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_countersObject

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

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/svg_conform/element_proxy.rb', line 22

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



22
23
24
# File 'lib/svg_conform/element_proxy.rb', line 22

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



22
23
24
# File 'lib/svg_conform/element_proxy.rb', line 22

def path
  @path
end

#positionObject (readonly)

Returns the value of attribute position.



22
23
24
# File 'lib/svg_conform/element_proxy.rb', line 22

def position
  @position
end

#raw_attributesObject (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_contentObject

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

#attributesObject

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

#columnObject



92
93
94
# File 'lib/svg_conform/element_proxy.rb', line 92

def column
  nil
end

#element_idObject

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

Returns:

  • (Boolean)


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

#lineObject

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

#namespaceObject

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_idObject

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

Returns:

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

Returns:

  • (Boolean)


68
69
70
# File 'lib/svg_conform/element_proxy.rb', line 68

def text?
  false
end