Class: Sumi::Graphics::Mixtures::Identify::Identifiers

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ void

Builds an id index for an element subtree.

Parameters:



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.

Returns:



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.

Returns:



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.

Returns:



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.

Parameters:

  • id (String) —

    serialized rendered SVG id

Returns:



46
# File 'graphics/lib/sumi/graphics/mixtures/identify.rb', line 46

def [](id) = @namespace[id]

#conflict? ⇒ Boolean

Reports whether duplicate ids were found.

Returns:

  • (Boolean)


38
39
40
# File 'graphics/lib/sumi/graphics/mixtures/identify.rb', line 38

def conflict?
  !@collision.empty?
end