Class: TkWrapper::Util::Tk::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/util/tk/finder.rb

Constant Summary collapse

Match =
TkWrapper::Widgets::Base::Match
Matcher =
TkWrapper::Widgets::Base::Matcher
Matches =
TkWrapper::Widgets::Base::Matches

Instance Method Summary collapse

Constructor Details

#initialize(widgets: nil, lookup: nil) ⇒ Finder

Returns a new instance of Finder.



12
13
14
15
# File 'lib/util/tk/finder.rb', line 12

def initialize(widgets: nil, lookup: nil)
  @lookup = lookup
  @widgets = widgets
end

Instance Method Details

#find(comparators, widgets = @widgets, lookup = @lookup) ⇒ Object



25
26
27
# File 'lib/util/tk/finder.rb', line 25

def find(comparators, widgets = @widgets, lookup = @lookup)
  iter(comparators, widgets, lookup, &:itself).first
end

#find_all(comparators, widgets = @widgets, lookup = @lookup) ⇒ Object



29
30
31
32
# File 'lib/util/tk/finder.rb', line 29

def find_all(comparators, widgets = @widgets, lookup = @lookup)
  it = iter(comparators, widgets, lookup, &:itself)
  it.each_with_object(Matches.new) { |match, matches| matches.push(match) }
end

#iter(comparators, widgets = @widgets, lookup = @lookup) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/util/tk/finder.rb', line 17

def iter(comparators, widgets = @widgets, lookup = @lookup)
  comparators = [comparators] unless comparators.is_a?(Array)
  Enumerator.new do |y|
    comparators = each_widget_lookup_match(lookup, comparators) { |m| y << m }
    each_widget_comparator_match(widgets, comparators) { |m| y << m }
  end
end