Class: Sevgi::Graphics::Attribute::Store Private
- Inherits:
-
Object
- Object
- Sevgi::Graphics::Attribute::Store
- Defined in:
- lib/sevgi/graphics/attribute.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Mutable backing store for SVG attributes.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
private
Returns a stored attribute value for the public facade.
-
#[]=(key, value) ⇒ Object?
private
Assigns a recursively owned attribute snapshot.
-
#delete(key) ⇒ Object?
private
Deletes an attribute by normalized key.
-
#export ⇒ Hash
private
Returns rendering attributes, excluding non-rendering metadata.
-
#has?(key) ⇒ Boolean
private
Reports whether an attribute exists.
-
#import(attributes) ⇒ Hash
private
Atomically imports recursively owned attribute snapshots.
-
#initialize(attributes = {}) ⇒ void
constructor
private
Creates an attribute store from recursively owned snapshots.
-
#initialize_copy(original) ⇒ void
private
Copies the attribute store with recursively independent values.
-
#list ⇒ Array<Symbol>
private
Returns rendering attribute names, excluding non-rendering metadata.
-
#to_h ⇒ Hash
private
Returns the internal attribute and metadata Hash.
-
#to_xml_lines ⇒ Array<String>
private
Returns rendered XML attribute lines.
Constructor Details
#initialize(attributes = {}) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates an attribute store from recursively owned snapshots. Mutable non-container leaves are stringified once; later caller mutation cannot change the store.
180 181 182 183 184 |
# File 'lib/sevgi/graphics/attribute.rb', line 180 def initialize(attributes = {}) @store = {} import(attributes) end |
Instance Method Details
#[](key) ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a stored attribute value for the public facade.
202 203 204 |
# File 'lib/sevgi/graphics/attribute.rb', line 202 def [](key) @store[Attribute.id(key)] end |
#[]=(key, value) ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Assigns a recursively owned attribute snapshot. Mutable non-container leaves are stringified once.
213 214 215 216 217 218 219 |
# File 'lib/sevgi/graphics/attribute.rb', line 213 def []=(key, value) return if value.nil? id = Attribute.id(key) value = Attribute.capture(value, normalize_keys: value.is_a?(::Hash)) @store[id] = @store.key?(id) && Attribute.updateable?(key) ? update(@store[id], value) : value end |
#delete(key) ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deletes an attribute by normalized key.
225 226 227 |
# File 'lib/sevgi/graphics/attribute.rb', line 225 def delete(key) @store.delete(Attribute.id(key)) end |
#export ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns rendering attributes, excluding non-rendering metadata. Nested values remain live store values.
231 232 233 234 235 236 237 |
# File 'lib/sevgi/graphics/attribute.rb', line 231 def export hash = @store.reject { |id, _| Attribute.internal?(id) } return hash unless hash.key?(:id) # Keep id first for stable, readable SVG output. {id: hash.delete(:id), **hash} end |
#has?(key) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reports whether an attribute exists.
243 244 245 |
# File 'lib/sevgi/graphics/attribute.rb', line 243 def has?(key) @store.key?(Attribute.id(key)) end |
#import(attributes) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Atomically imports recursively owned attribute snapshots.
191 192 193 194 195 196 |
# File 'lib/sevgi/graphics/attribute.rb', line 191 def import(attributes) updated = @store.dup entries(attributes).each { |entry| assign(updated, *entry) } @store.replace(updated) end |
#initialize_copy(original) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Copies the attribute store with recursively independent values.
250 251 252 253 254 255 |
# File 'lib/sevgi/graphics/attribute.rb', line 250 def initialize_copy(original) @store = {} original.store.each { |key, value| @store[key] = Attribute.capture(value) } super end |
#list ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns rendering attribute names, excluding non-rendering metadata.
259 260 261 |
# File 'lib/sevgi/graphics/attribute.rb', line 259 def list export.keys end |
#to_h ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the internal attribute and metadata Hash.
265 266 267 |
# File 'lib/sevgi/graphics/attribute.rb', line 265 def to_h @store end |
#to_xml_lines ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns rendered XML attribute lines.
272 273 274 |
# File 'lib/sevgi/graphics/attribute.rb', line 272 def to_xml_lines export.map { |id, value| to_xml(id, value) } end |