Class: Punchout::Puncher::Matchables

Inherits:
Object
  • Object
show all
Defined in:
lib/punchout/puncher/matchables.rb

Overview

Note:

If two matchers would trigger on the item passed, the first matcher added wins.

Sanity checks and stores the Matchables behind a Punchout::Puncher

Instance Method Summary collapse

Constructor Details

#initializeMatchables

Returns a new instance of Matchables.



9
10
11
# File 'lib/punchout/puncher/matchables.rb', line 9

def initialize
  @matchables = []
end

Instance Method Details

#add(matchable) ⇒ Object



13
14
15
16
17
18
# File 'lib/punchout/puncher/matchables.rb', line 13

def add(matchable)
  if conflicts?(matchable)
    raise
  end
  @matchables << matchable
end

#allObject



32
33
34
# File 'lib/punchout/puncher/matchables.rb', line 32

def all
  @matchables
end

#find(type) ⇒ Object



26
27
28
29
30
# File 'lib/punchout/puncher/matchables.rb', line 26

def find(type)
  @matchables.find do |p|
    p.matches?(type)
  end
end

#include?(type) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/punchout/puncher/matchables.rb', line 20

def include?(type)
  @matchables.any? do |p|
    p.matches?(type)
  end
end