Class: Sevgi::Graphics::Document::Profile
- Inherits:
-
Object
- Object
- Sevgi::Graphics::Document::Profile
- 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.
Instance Attribute Summary collapse
-
#name ⇒ Symbol?
readonly
Profile name.
Class Method Summary collapse
-
.[](name) ⇒ Class?
Returns a profile class by name from the process-global registry.
-
.available ⇒ Hash<Symbol, Class>
Returns a thread-coherent immutable snapshot of registered profile classes.
-
.normalize(name) ⇒ Symbol?
Normalizes a profile name.
-
.normalize!(name) ⇒ Symbol
Normalizes a profile name or raises.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Reports strict profile equality.
-
#attributes ⇒ Hash
Returns default root attributes.
-
#deconstruct ⇒ Array<(Symbol, nil), Hash, (Array<String>, nil)>
Returns profile components.
-
#initialize(name, attributes: nil, preambles: nil) ⇒ void
constructor
Creates profile metadata.
-
#preambles ⇒ Array<String>?
Returns preamble lines.
Constructor Details
#initialize(name, attributes: nil, preambles: nil) ⇒ void
Creates profile metadata.
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
#name ⇒ Symbol? (readonly)
Returns 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.
230 |
# File 'lib/sevgi/graphics/document.rb', line 230 def self.[](name) = (name = normalize(name)) && Registry[name] |
.available ⇒ Hash<Symbol, Class>
Returns a thread-coherent immutable snapshot of registered profile classes.
225 |
# File 'lib/sevgi/graphics/document.rb', line 225 def self.available = Registry.available |
.normalize(name) ⇒ Symbol?
Normalizes a profile name.
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.
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.
267 |
# File 'lib/sevgi/graphics/document.rb', line 267 def ==(other) = self.class == other.class && deconstruct == other.deconstruct |
#attributes ⇒ Hash
Returns default root attributes.
271 |
# File 'lib/sevgi/graphics/document.rb', line 271 def attributes = Snapshot.copy(@attributes) |
#deconstruct ⇒ Array<(Symbol, nil), Hash, (Array<String>, nil)>
Returns profile components.
275 |
# File 'lib/sevgi/graphics/document.rb', line 275 def deconstruct = [name, attributes, preambles] |
#preambles ⇒ Array<String>?
Returns preamble lines.
279 |
# File 'lib/sevgi/graphics/document.rb', line 279 def preambles = Snapshot.copy(@preambles) |