Class: TkWrapper::Widgets::Base::ComparatorItemStore
- Inherits:
-
Object
- Object
- TkWrapper::Widgets::Base::ComparatorItemStore
- Defined in:
- lib/widgets/base/comparator_item_store.rb
Constant Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize ⇒ ComparatorItemStore
constructor
A new instance of ComparatorItemStore.
-
#items_and_matches_for_widget(widget) ⇒ Object
returns [[…], match: Match, […], …].
- #map_key?(key) ⇒ Boolean
- #push(key, *items) ⇒ Object
Constructor Details
#initialize ⇒ ComparatorItemStore
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
#[](key) ⇒ Object
32 33 34 35 |
# File 'lib/widgets/base/comparator_item_store.rb', line 32 def [](key) items = map_key?(key) ? @key_map[key] : @comparator_map[key] items&.length == 1 ? items.first : items end |
#items_and_matches_for_widget(widget) ⇒ Object
returns [[…], match: Match, […], …]
26 27 28 29 30 |
# File 'lib/widgets/base/comparator_item_store.rb', line 26 def () .ids.reduce([]) do |items, id| items + items_from_key_map(id) + items_from_comparator_map(id, ) end end |
#map_key?(key) ⇒ Boolean
13 14 15 |
# File 'lib/widgets/base/comparator_item_store.rb', line 13 def map_key?(key) [String, Symbol].include?(key) end |
#push(key, *items) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/widgets/base/comparator_item_store.rb', line 17 def push(key, *items) if map_key?(key) (@key_map[key] ||= []).concat(items) else (@comparator_map[key] ||= []).concat(items) end end |