Class: Sumi::Graphics::Mixtures::Identify::Identifiers
- Inherits:
-
Object
- Object
- Sumi::Graphics::Mixtures::Identify::Identifiers
- Defined in:
- graphics/lib/sumi/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<Sumi::Graphics::Element>>
readonly
Frozen duplicate groups keyed by serialized ids.
-
#element ⇒ Sumi::Graphics::Element
readonly
Indexed root element.
-
#namespace ⇒ Hash<String, Sumi::Graphics::Element>
readonly
Frozen namespace keyed by serialized rendered ids.
Instance Method Summary collapse
-
#[](id) ⇒ Sumi::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 'graphics/lib/sumi/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<Sumi::Graphics::Element>> (readonly)
Returns frozen duplicate groups keyed by serialized ids.
19 20 21 |
# File 'graphics/lib/sumi/graphics/mixtures/identify.rb', line 19 def collision @collision end |
#element ⇒ Sumi::Graphics::Element (readonly)
Returns indexed root element.
13 14 15 |
# File 'graphics/lib/sumi/graphics/mixtures/identify.rb', line 13 def element @element end |
#namespace ⇒ Hash<String, Sumi::Graphics::Element> (readonly)
Returns frozen namespace keyed by serialized rendered ids.
16 17 18 |
# File 'graphics/lib/sumi/graphics/mixtures/identify.rb', line 16 def namespace @namespace end |
Instance Method Details
#[](id) ⇒ Sumi::Graphics::Element?
Returns the first element registered for an id in the snapshot. Duplicate entries are available through #collision.
46 |
# File 'graphics/lib/sumi/graphics/mixtures/identify.rb', line 46 def [](id) = @namespace[id] |
#conflict? ⇒ Boolean
Reports whether duplicate ids were found.
38 39 40 |
# File 'graphics/lib/sumi/graphics/mixtures/identify.rb', line 38 def conflict? !@collision.empty? end |