Class: Sumi::Derender::Node

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

Instance Method Summary collapse

Instance Attribute Details

#attributes ⇒ Hash{String => String} (readonly)

Returns immutable XML attributes.

Returns:

  • (Hash{String => String}) —

    owned attribute snapshot



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.

Returns:



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.

Returns:

  • (String) —

    frozen owned text snapshot



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.

Returns:

  • (String) —

    owned 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.

Returns:

  • (Hash{String => String}) —

    frozen owned namespace snapshot



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.

Returns:

  • (Hash{String => String}) —

    immutable metadata snapshot



251
# File 'derender/lib/sumi/derender/node.rb', line 251

def _ = @meta

#derender ⇒ String

Note:

Foreign namespace elements use the explicit Element DSL path, and nested svg nodes remain elements.

Note:

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.

Returns:

  • (String) —

    formatted Sumi DSL source

Raises:



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?

Note:

Namespace declarations, qualified attributes, significant text, and nested svg nodes are preserved.

Evaluates this node under a graphics element.

Parameters:

Returns:



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.

Parameters:

Returns:



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?

Note:

Attributes omitted during decompilation are unavailable for later searches.

Finds this node or the first descendant whose attribute matches a value.

Parameters:

  • arg (String) —

    attribute value to find

  • by (String) (defaults to: "id") —

    attribute name used for lookup

Returns:



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.

Returns:

  • (Boolean) —

    true for the conversion root strategy



288
# File 'derender/lib/sumi/derender/node.rb', line 288

def root? = @type == :Root