Class: Sevgi::Graphics::Document::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/sevgi/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.

See Also:

  • Sevgi::Graphics.document

Instance Attribute Summary collapse

Class Method 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:

  • (Sevgi::ArgumentError)

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



257
258
259
260
261
262
# File 'lib/sevgi/graphics/document.rb', line 257

def initialize(name, attributes: nil, preambles: nil)
  @name = name.nil? ? nil : self.class.normalize!(name)
  validate_attributes!(attributes)
  @attributes = Snapshot.capture(attributes || {})
  @preambles = capture_preambles(preambles)
end

Instance Attribute Details

#nameSymbol? (readonly)

Returns profile name.

Returns:

  • (Symbol, nil)

    profile name



249
250
251
# File 'lib/sevgi/graphics/document.rb', line 249

def name
  @name
end

Class Method Details

.[](name) ⇒ Class?

Returns a profile class by name from the process-global registry.

Parameters:

  • name (Object)

    profile name

Returns:

  • (Class, nil)


230
# File 'lib/sevgi/graphics/document.rb', line 230

def self.[](name) = (name = normalize(name)) && Registry[name]

.availableHash<Symbol, Class>

Returns a thread-coherent immutable snapshot of registered profile classes.

Returns:

  • (Hash<Symbol, Class>)


225
# File 'lib/sevgi/graphics/document.rb', line 225

def self.available = Registry.available

.normalize(name) ⇒ Symbol?

Normalizes a profile name.

Parameters:

  • name (Object)

    profile name

Returns:

  • (Symbol, nil)


235
236
237
238
239
240
# File 'lib/sevgi/graphics/document.rb', line 235

def self.normalize(name)
  normalized = name.to_sym if name.respond_to?(:to_sym)
  normalized if normalized.is_a?(::Symbol)
rescue ::StandardError
  nil
end

.normalize!(name) ⇒ Symbol

Normalizes a profile name or raises.

Parameters:

  • name (Object)

    profile name

Returns:

  • (Symbol)

Raises:

  • (Sevgi::ArgumentError)

    when name cannot be normalized



246
# File 'lib/sevgi/graphics/document.rb', line 246

def self.normalize!(name) = normalize(name) || ArgumentError.("Invalid document profile: #{name}")

Instance Method Details

#==(other) ⇒ Boolean

Reports strict profile equality.

Parameters:

  • other (Object)

    object to compare

Returns:

  • (Boolean)


267
# File 'lib/sevgi/graphics/document.rb', line 267

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

#attributesHash

Returns default root attributes.

Returns:

  • (Hash)

    mutation-isolated attribute snapshot



271
# File 'lib/sevgi/graphics/document.rb', line 271

def attributes = Snapshot.copy(@attributes)

#deconstructArray<(Symbol, nil), Hash, (Array<String>, nil)>

Returns profile components.

Returns:

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


275
# File 'lib/sevgi/graphics/document.rb', line 275

def deconstruct = [name, attributes, preambles]

#preamblesArray<String>?

Returns preamble lines.

Returns:

  • (Array<String>, nil)

    mutation-isolated preamble snapshot



279
# File 'lib/sevgi/graphics/document.rb', line 279

def preambles = Snapshot.copy(@preambles)