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

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(widgets: nil) ⇒ Finder

Returns a new instance of Finder.



10
11
12
# File 'lib/util/tk/finder.rb', line 10

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

Instance Method Details

#each_widget_match(widgets, matchers, &block) ⇒ Object



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

def each_widget_match(widgets, matchers, &block)
  widgets.each do |widget|
    widget.ids.each do |id|
      matchers.each do |matcher|
        (match = matcher.match(id, widget)) && block.call(match)
      end
    end
  end
end

#find_all_widgets(comparators, widgets = @widgets) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/util/tk/finder.rb', line 32

def find_all_widgets(comparators, widgets = @widgets)
  matchers = create_value_matchers(comparators)
  matches = TkWrapper::Widgets::Base::Matches.new

  each_widget_match(widgets, matchers) do |match|
    matches.push(match)
  end

  matches
end

#find_widget(comparators, widgets = @widgets) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/util/tk/finder.rb', line 24

def find_widget(comparators, widgets = @widgets)
  matchers = create_value_matchers(comparators)

  each_widget_match(widgets, matchers) do |match|
    return match.widget if match
  end
end