Class: TkWrapper::Widgets::Base::Matches

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/widgets/base/matches.rb

Overview

matches widgets against conditions and stores matching widgets and matches

Instance Method Summary collapse

Constructor Details

#initializeMatches

Returns a new instance of Matches.



7
8
9
# File 'lib/widgets/base/matches.rb', line 7

def initialize
  @matches = {}
end

Instance Method Details

#[](key) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/widgets/base/matches.rb', line 27

def [](key)
  case @matches[key]&.size
  when 0, nil then nil
  when 1      then @matches[key][0]
  else             @matches[key]
  end
end

#concat(matches) ⇒ Object



15
16
17
# File 'lib/widgets/base/matches.rb', line 15

def concat(matches)
  matches.each { |match| push(match) }
end

#each(&block) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/widgets/base/matches.rb', line 19

def each(&block)
  @matches.each do |(key, matches_for_key)|
    matches_for_key.each do |match|
      block.call([match.widget, key, match.match, match])
    end
  end
end

#firstObject



35
36
37
# File 'lib/widgets/base/matches.rb', line 35

def first
  @matches.first&.[](1)
end

#push(match) ⇒ Object



11
12
13
# File 'lib/widgets/base/matches.rb', line 11

def push(match)
  (@matches[match.key] ||= []).push(match)
end