Class: FilterMatcher::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/filter_matcher/filter_matcher.rb

Defined Under Namespace

Classes: FirstFromTopMatcher, SingleMatcher, UnknownMatcherError

Constant Summary collapse

MATCHERS =
[:single, :first_from_top]

Instance Method Summary collapse

Constructor Details

#initialize(collection, matcher_type) ⇒ Matcher

Returns a new instance of Matcher.



8
9
10
11
12
13
14
15
16
# File 'lib/filter_matcher/filter_matcher.rb', line 8

def initialize(collection, matcher_type)
  unless MATCHERS.include?(matcher_type)
    raise UnknownMatcherError,
      "No matcher #{matcher_type} found, select one of these: #{MATCHERS.join(', ')}"
  end

  @collection = collection
  @matcher = self.class.get_matcher(matcher_type)
end

Instance Method Details

#filter(&block) ⇒ Object



18
19
20
# File 'lib/filter_matcher/filter_matcher.rb', line 18

def filter(&block)
  @matcher.filters << block
end

#match(&block) ⇒ Object



22
23
24
# File 'lib/filter_matcher/filter_matcher.rb', line 22

def match(&block)
  @match = block
end

#runObject



26
27
28
# File 'lib/filter_matcher/filter_matcher.rb', line 26

def run
  @matcher.run(@collection, @match)
end