Class: Sevgi::Derender::Node
- Inherits:
-
Object
- Object
- Sevgi::Derender::Node
- Defined in:
- lib/sevgi/derender/node.rb
Overview
Immutable conversion result for one SVG/XML node.
Attributes, namespaces, content, and descendants are owned snapshots; parser objects and dispatch strategies remain internal to Derender. Attributes omitted during decompilation are absent throughout the captured subtree.
Instance Attribute Summary collapse
-
#attributes ⇒ Hash{String => String}
readonly
Returns immutable XML attributes.
-
#children ⇒ Array<Sevgi::Derender::Node>
readonly
Returns immutable child nodes.
-
#content ⇒ String
readonly
Returns immutable normalized text content.
-
#name ⇒ String
readonly
Returns the immutable qualified element name.
-
#namespaces ⇒ Hash{String => String}
readonly
Returns immutable namespace declarations emitted for this node.
Instance Method Summary collapse
-
#_ ⇒ Hash{String => String}
(also: #meta)
Returns Sevgi metadata attributes without the metadata namespace prefix.
-
#derender ⇒ String
Converts this node into formatted Sevgi DSL Ruby source.
-
#evaluate(element) ⇒ Sevgi::Graphics::Element?
Evaluates this node under a graphics element.
-
#evaluate_children(element) ⇒ Array<Sevgi::Graphics::Element>
Evaluates only this node's children under a graphics element.
-
#find(arg, by: "id") ⇒ Sevgi::Derender::Node?
Finds this node or the first descendant whose attribute matches a value.
-
#initialize(node, pres = [], namespaces: nil, omit: nil, top: true) ⇒ void
constructor
private
Builds an owned derender result.
-
#root? ⇒ Boolean
Reports whether this node represents an SVG document root.
Constructor Details
#initialize(node, pres = [], namespaces: nil, omit: nil, top: true) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds an owned derender result.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/sevgi/derender/node.rb', line 114 def initialize(node, pres = [], namespaces: nil, omit: nil, top: true) @node = node @omit = omit || {}.freeze @top = top capture_context(pres, namespaces) capture_values capture_children capture_identity freeze end |
Instance Attribute Details
#attributes ⇒ Hash{String => String} (readonly)
Returns immutable XML attributes.
86 87 88 |
# File 'lib/sevgi/derender/node.rb', line 86 def attributes @attributes end |
#children ⇒ Array<Sevgi::Derender::Node> (readonly)
Returns immutable child nodes.
90 91 92 |
# File 'lib/sevgi/derender/node.rb', line 90 def children @children end |
#content ⇒ String (readonly)
Returns immutable normalized text content. xml:space="preserve" and single-line mixed text retain their exact
text. Other text trims surrounding whitespace; multiline mixed text removes only its outer indentation lines.
95 96 97 |
# File 'lib/sevgi/derender/node.rb', line 95 def content @content end |
#name ⇒ String (readonly)
Returns the immutable qualified element name.
99 100 101 |
# File 'lib/sevgi/derender/node.rb', line 99 def name @name end |
#namespaces ⇒ Hash{String => String} (readonly)
Returns immutable namespace declarations emitted for this node. A conversion root owns its local declarations; a separately selected node owns all declarations in scope; descendant snapshots own their local declarations.
104 105 106 |
# File 'lib/sevgi/derender/node.rb', line 104 def namespaces @namespaces end |
Instance Method Details
#_ ⇒ Hash{String => String} Also known as: meta
Returns Sevgi metadata attributes without the metadata namespace prefix.
127 |
# File 'lib/sevgi/derender/node.rb', line 127 def _ = @meta |
#derender ⇒ String
Foreign namespace elements use the explicit Element DSL path, and nested svg nodes remain elements.
Unsafe bare Ruby names are emitted through the explicit Element DSL word.
Converts this node into formatted Sevgi DSL Ruby source.
136 |
# File 'lib/sevgi/derender/node.rb', line 136 def derender = Ruby.format(decompile(@pres).join("\n")) |
#evaluate(element) ⇒ Sevgi::Graphics::Element?
Namespace declarations, qualified attributes, significant text, and nested svg nodes are preserved.
Evaluates this node under a graphics element.
142 |
# File 'lib/sevgi/derender/node.rb', line 142 def evaluate(element) = Evaluator.new(element).append(self) |
#evaluate_children(element) ⇒ Array<Sevgi::Graphics::Element>
Evaluates only this node's children under a graphics element.
147 |
# File 'lib/sevgi/derender/node.rb', line 147 def evaluate_children(element) = children.filter_map { it.evaluate(element) }.freeze |
#find(arg, by: "id") ⇒ Sevgi::Derender::Node?
Attributes omitted during decompilation are unavailable for later searches.
Finds this node or the first descendant whose attribute matches a value.
154 155 156 157 158 |
# File 'lib/sevgi/derender/node.rb', line 154 def find(arg, by: "id") return self if attributes[by] == arg children.lazy.map { it.find(arg, by:) }.find(&:itself) end |
#root? ⇒ Boolean
Reports whether this node represents an SVG document root.
162 |
# File 'lib/sevgi/derender/node.rb', line 162 def root? = @type == :Root |