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 SVG attribute store with Sevgi update syntax.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
private
Returns an attribute by normalized key.
-
#[]=(key, value) ⇒ Object?
private
Assigns an attribute value.
-
#delete(key) ⇒ Object?
private
Deletes an attribute by normalized key.
-
#export ⇒ Hash
private
Returns public attributes ready for rendering.
-
#has?(key) ⇒ Boolean
private
Reports whether an attribute exists.
-
#import(attributes) ⇒ Hash
private
Imports attributes into the store.
-
#initialize(attributes = {}) ⇒ void
constructor
private
Creates an attribute store.
-
#initialize_copy(original) ⇒ void
private
Copies the attribute store.
-
#list ⇒ Array<Symbol>
private
Returns public attribute names.
-
#to_h ⇒ Hash
private
Returns the internal attribute 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.
64 65 66 67 68 |
# File 'lib/sevgi/graphics/attribute.rb', line 64 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 an attribute by normalized key.
87 88 89 |
# File 'lib/sevgi/graphics/attribute.rb', line 87 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 an attribute value.
97 98 99 100 101 |
# File 'lib/sevgi/graphics/attribute.rb', line 97 def []=(key, value) return if value.nil? @store[id = Attribute.id(key)] = @store.key?(id) && Attribute.updateable?(key) ? update(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.
106 107 108 |
# File 'lib/sevgi/graphics/attribute.rb', line 106 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 public attributes ready for rendering.
112 113 114 115 116 117 118 |
# File 'lib/sevgi/graphics/attribute.rb', line 112 def export hash = @store.reject { |id, _| Attribute.internal?(id) } return hash unless hash.key?(:id) # A small aesthetic touch: always keep the id attribute first {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.
123 124 125 |
# File 'lib/sevgi/graphics/attribute.rb', line 123 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.
Imports attributes into the store.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/sevgi/graphics/attribute.rb', line 73 def import(attributes) hash = attributes .compact .to_a .to_h do |key, value| [key.to_sym, import_value(value)] end @store.merge!(hash) 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.
130 131 132 133 134 135 |
# File 'lib/sevgi/graphics/attribute.rb', line 130 def initialize_copy(original) @store = {} original.store.each { |key, value| @store[key] = value.dup } 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 public attribute names.
139 140 141 |
# File 'lib/sevgi/graphics/attribute.rb', line 139 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 hash.
145 146 147 |
# File 'lib/sevgi/graphics/attribute.rb', line 145 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.
151 152 153 |
# File 'lib/sevgi/graphics/attribute.rb', line 151 def to_xml_lines export.map { |id, value| to_xml(id, value) } end |