Class: Rounders::Matchers::Matcher

Inherits:
Object
  • Object
show all
Includes:
Plugins::Pluggable
Defined in:
lib/rounders/matchers/matcher.rb

Direct Known Subclasses

Body, CC, Filename, From, Subject, To

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugins::Pluggable

included

Constructor Details

#initialize(matchers) ⇒ Matcher

Returns a new instance of Matcher.



12
13
14
# File 'lib/rounders/matchers/matcher.rb', line 12

def initialize(matchers)
  @matchers = matchers
end

Instance Attribute Details

#matchersObject (readonly)

Returns the value of attribute matchers.



10
11
12
# File 'lib/rounders/matchers/matcher.rb', line 10

def matchers
  @matchers
end

Class Method Details

.build(conditions) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/rounders/matchers/matcher.rb', line 30

def build(conditions)
  matchers = conditions.map do |key, pattern|
    matcher = Rounders.matchers[key]
    raise Rounders::Matchers::NoImplementError if matcher.nil?
    matcher.new(pattern)
  end
  new(matchers)
rescue StandardError => e
  raise e
end

.inherited(klass) ⇒ Object



25
26
27
28
# File 'lib/rounders/matchers/matcher.rb', line 25

def inherited(klass)
  super
  Rounders.matchers[klass.symbol] = klass
end

Instance Method Details

#match(message) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rounders/matchers/matcher.rb', line 16

def match(message)
  match_data = matchers.each_with_object({}) do |matcher, memo|
    memo[matcher.class.symbol] = matcher.match(message)
  end
  return match_data if match_data.values.none? { |value| Util.blank?(value) }
  nil
end