Class: TkWrapper::Widgets::Base::ComparatorItemStore

Inherits:
Object
  • Object
show all
Defined in:
lib/widgets/base/comparator_item_store.rb

Constant Summary collapse

Matcher =
TkWrapper::Widgets::Base::Matcher

Instance Method Summary collapse

Constructor Details

#initializeComparatorItemStore

Returns a new instance of ComparatorItemStore.



8
9
10
11
# File 'lib/widgets/base/comparator_item_store.rb', line 8

def initialize
  @key_map = {}        # for fast lookup
  @comparator_map = {} # for lookup using comparisons by Matcher class
end

Instance Method Details

#items_and_matches_for_widget(widget) ⇒ Object

returns [[…], match: Match, […], …]



22
23
24
25
26
# File 'lib/widgets/base/comparator_item_store.rb', line 22

def items_and_matches_for_widget(widget)
  widget.ids.reduce([]) do |items, id|
    items + items_from_key_map(id) + items_from_comparator_map(id, widget)
  end
end

#push(key, *items) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/widgets/base/comparator_item_store.rb', line 13

def push(key, *items)
  if [String, Symbol].include?(key)
    (@key_map[key] ||= []).concat(items)
  else
    (@comparator_map[key] ||= []).concat(items)
  end
end