Class: Sumi::Derender::Node
- Inherits:
-
Object
- Object
- Sumi::Derender::Node
- Defined in:
- derender/lib/sumi/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<Sumi::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 Sumi metadata attributes without the metadata namespace prefix.
-
#derender ⇒ String
Converts this node into formatted Sumi DSL Ruby source.
-
#evaluate(element) ⇒ Sumi::Graphics::Element?
Evaluates this node under a graphics element.
-
#evaluate_children(element) ⇒ Array<Sumi::Graphics::Element>
Evaluates only this node's children under a graphics element.
-
#find(arg, by: "id") ⇒ Sumi::Derender::Node?
Finds this node or the first descendant whose attribute matches a value.
-
#root? ⇒ Boolean
Reports whether this node represents an SVG document root.
Instance Attribute Details
#attributes ⇒ Hash{String => String} (readonly)
Returns immutable XML attributes.
209 210 211 |
# File 'derender/lib/sumi/derender/node.rb', line 209 def attributes @attributes end |
#children ⇒ Array<Sumi::Derender::Node> (readonly)
Returns immutable child nodes.
213 214 215 |
# File 'derender/lib/sumi/derender/node.rb', line 213 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.
For a processing instruction, content is its complete XML markup, including the target and data.
219 220 221 |
# File 'derender/lib/sumi/derender/node.rb', line 219 def content @content end |
#name ⇒ String (readonly)
Returns the immutable qualified element name.
223 224 225 |
# File 'derender/lib/sumi/derender/node.rb', line 223 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. Independent source conversion and evaluation also emit the inherited declarations captured for that node.
229 230 231 |
# File 'derender/lib/sumi/derender/node.rb', line 229 def namespaces @namespaces end |
Instance Method Details
#_ ⇒ Hash{String => String} Also known as: meta
Returns Sumi metadata attributes without the metadata namespace prefix.
251 |
# File 'derender/lib/sumi/derender/node.rb', line 251 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 Sumi DSL Ruby source. The returned String is ordinary Ruby source. Review and integrate it statically rather than using Ruby's raw dynamic evaluation methods.
261 |
# File 'derender/lib/sumi/derender/node.rb', line 261 def derender = Ruby.format(decompile(@pres, namespaces: @scope).join("\n")) |
#evaluate(element) ⇒ Sumi::Graphics::Element?
Namespace declarations, qualified attributes, significant text, and nested svg nodes are preserved.
Evaluates this node under a graphics element.
267 |
# File 'derender/lib/sumi/derender/node.rb', line 267 def evaluate(element) = Evaluator.new(element).append(self, namespaces: @scope) |
#evaluate_children(element) ⇒ Array<Sumi::Graphics::Element>
Evaluates only this node's children under a graphics element. Each imported element retains its namespace scope without changing the target parent's declarations.
273 |
# File 'derender/lib/sumi/derender/node.rb', line 273 def evaluate_children(element) = children.filter_map { it.evaluate(element) }.freeze |
#find(arg, by: "id") ⇒ Sumi::Derender::Node?
Attributes omitted during decompilation are unavailable for later searches.
Finds this node or the first descendant whose attribute matches a value.
280 281 282 283 284 |
# File 'derender/lib/sumi/derender/node.rb', line 280 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.
288 |
# File 'derender/lib/sumi/derender/node.rb', line 288 def root? = @type == :Root |