Class: Sevgi::Graphics::Mixtures::Identify::Identifiers
- Inherits:
-
Object
- Object
- Sevgi::Graphics::Mixtures::Identify::Identifiers
- Defined in:
- lib/sevgi/graphics/mixtures/identify.rb
Overview
Immutable snapshot of every rendered element id under a subtree. Keys are the serialized id values, including
"false" and the empty String. Keys and containers are owned by the index; values retain references to the
elements present when the snapshot is built. Later tree changes require a new index.
Instance Attribute Summary collapse
-
#collision ⇒ Hash<String, Array<Sevgi::Graphics::Element>>
readonly
Frozen duplicate groups keyed by serialized ids.
-
#element ⇒ Sevgi::Graphics::Element
readonly
Indexed root element.
-
#namespace ⇒ Hash<String, Sevgi::Graphics::Element>
readonly
Frozen namespace keyed by serialized rendered ids.
Instance Method Summary collapse
-
#[](id) ⇒ Sevgi::Graphics::Element?
Returns the first element registered for an id in the snapshot.
-
#conflict? ⇒ Boolean
Reports whether duplicate ids were found.
-
#initialize(element) ⇒ void
constructor
Builds an id index for an element subtree.
Constructor Details
#initialize(element) ⇒ void
Builds an id index for an element subtree.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sevgi/graphics/mixtures/identify.rb', line 24 def initialize(element) @element = element @namespace = {} @collision = {} build @namespace.freeze @collision.each_value(&:freeze) @collision.freeze freeze end |
Instance Attribute Details
#collision ⇒ Hash<String, Array<Sevgi::Graphics::Element>> (readonly)
Returns frozen duplicate groups keyed by serialized ids.
19 20 21 |
# File 'lib/sevgi/graphics/mixtures/identify.rb', line 19 def collision @collision end |
#element ⇒ Sevgi::Graphics::Element (readonly)
Returns indexed root element.
13 14 15 |
# File 'lib/sevgi/graphics/mixtures/identify.rb', line 13 def element @element end |
#namespace ⇒ Hash<String, Sevgi::Graphics::Element> (readonly)
Returns frozen namespace keyed by serialized rendered ids.
16 17 18 |
# File 'lib/sevgi/graphics/mixtures/identify.rb', line 16 def namespace @namespace end |
Instance Method Details
#[](id) ⇒ Sevgi::Graphics::Element?
Returns the first element registered for an id in the snapshot. Duplicate entries are available through #collision.
46 |
# File 'lib/sevgi/graphics/mixtures/identify.rb', line 46 def [](id) = @namespace[id] |
#conflict? ⇒ Boolean
Reports whether duplicate ids were found.
38 39 40 |
# File 'lib/sevgi/graphics/mixtures/identify.rb', line 38 def conflict? !@collision.empty? end |