Class: TkWrapper::Widgets::Base::Matches
- Inherits:
-
Object
- Object
- TkWrapper::Widgets::Base::Matches
- Includes:
- Enumerable
- Defined in:
- lib/widgets/base/matches.rb
Overview
matches widgets against conditions and stores matching widgets and matches
Instance Method Summary collapse
- #[](key) ⇒ Object
- #concat(matches) ⇒ Object
- #each(&block) ⇒ Object
- #first ⇒ Object
-
#initialize ⇒ Matches
constructor
A new instance of Matches.
- #push(match) ⇒ Object
Constructor Details
#initialize ⇒ Matches
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., key, match.match, match]) end end end |
#first ⇒ Object
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 |