Class: Sumi::Graphics::Document::Profile

Inherits:
Object
  • Object
show all
Defined in:
graphics/lib/sumi/graphics/document.rb

Overview

Immutable, read-only document profile metadata exposed by document classes. Process-global lookup and registration are thread-atomic. Metadata containers and strings are captured recursively. Other mutable attribute values are stringified once during construction. Attribute names and nested Hash keys are normalized to Symbols, nil values are omitted, and update-suffix intent is retained for inheritance. Returned attribute and preamble collections are caller-owned snapshots, so changing them does not alter the registered profile.

See Also:

  • Sumi::Graphics.document

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attributes: nil, preambles: nil) ⇒ void

Creates profile metadata.

Parameters:

  • name (Object, nil) —

    profile name

  • attributes (Hash, nil) (defaults to: nil) —

    default root attributes. Nil means an empty Hash

  • preambles (Array<String>, nil) (defaults to: nil) —

    preamble lines

Raises:

  • (Sumi::ArgumentError) —

    when name or metadata is invalid XML, cyclic, or cannot be stringified



264
265
266
267
268
269
# File 'graphics/lib/sumi/graphics/document.rb', line 264

def initialize(name, attributes: nil, preambles: nil)
  @name = name.nil? ? nil : Name.normalize!(name)
  @attributes = capture_attributes(attributes)
  @preambles = capture_preambles(preambles)
  freeze
end

Instance Attribute Details

#name ⇒ Symbol? (readonly)

Returns profile name.

Returns:

  • (Symbol, nil) —

    profile name



256
257
258
# File 'graphics/lib/sumi/graphics/document.rb', line 256

def name
  @name
end

Instance Method Details

#attributes ⇒ Hash{Symbol => Object}

Returns canonical default root attributes for this profile. Names and nested Hash keys are Symbols, nil attributes are omitted, and update suffixes remain explicit for application by a document class.

Returns:

  • (Hash{Symbol => Object}) —

    mutation-isolated attribute snapshot



284
# File 'graphics/lib/sumi/graphics/document.rb', line 284

def attributes = Snapshot.copy(@attributes)

#deconstruct ⇒ Array<(Symbol, nil), Hash, (Array<String>, nil)>

Returns profile components.

Returns:

  • (Array<(Symbol, nil), Hash, (Array<String>, nil)>)


288
# File 'graphics/lib/sumi/graphics/document.rb', line 288

def deconstruct = [name, attributes, preambles]

#eql?(other) ⇒ Boolean Also known as: ==

Reports strict profile equality.

Parameters:

  • other (Object) —

    object to compare

Returns:

  • (Boolean)


274
# File 'graphics/lib/sumi/graphics/document.rb', line 274

def eql?(other) = self.class == other.class && deconstruct == other.deconstruct

#hash ⇒ Integer

Returns a hash compatible with strict equality.

Returns:

  • (Integer)


278
# File 'graphics/lib/sumi/graphics/document.rb', line 278

def hash = [self.class, name, @attributes, @preambles].hash

#preambles ⇒ Array<String>?

Returns preamble lines.

Returns:

  • (Array<String>, nil) —

    mutation-isolated preamble snapshot



292
# File 'graphics/lib/sumi/graphics/document.rb', line 292

def preambles = Snapshot.copy(@preambles)