class Punchout::Puncher::Matchables
Sanity checks and stores the Matchables
behind a {Puncher}
@note If two matchers would trigger on the item passed, the first
matcher added wins.
Public Class Methods
new()
click to toggle source
# File lib/punchout/puncher/matchables.rb, line 9 def initialize @matchables = [] end
Public Instance Methods
add(matchable)
click to toggle source
# File lib/punchout/puncher/matchables.rb, line 13 def add(matchable) if conflicts?(matchable) raise end @matchables << matchable end
all()
click to toggle source
# File lib/punchout/puncher/matchables.rb, line 32 def all @matchables end
find(type)
click to toggle source
# File lib/punchout/puncher/matchables.rb, line 26 def find(type) @matchables.find do |p| p.matches?(type) end end
include?(type)
click to toggle source
# File lib/punchout/puncher/matchables.rb, line 20 def include?(type) @matchables.any? do |p| p.matches?(type) end end
Private Instance Methods
conflicts?(matchable)
click to toggle source
# File lib/punchout/puncher/matchables.rb, line 38 def conflicts?(matchable) @matchables.any? do |m| m.conflicts?(matchable) || matchable.conflicts?(m) end end