Class: Rounders::Matchers::Matcher
- Inherits:
-
Object
- Object
- Rounders::Matchers::Matcher
- Includes:
- Plugins::Pluggable
- Defined in:
- lib/rounders/matchers/matcher.rb
Instance Attribute Summary collapse
-
#matchers ⇒ Object
readonly
Returns the value of attribute matchers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(matchers) ⇒ Matcher
constructor
A new instance of Matcher.
- #match(message) ⇒ Object
Methods included from Plugins::Pluggable
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
#matchers ⇒ Object (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 |
Instance Method Details
#match(message) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rounders/matchers/matcher.rb', line 16 def match() match_data = matchers.each_with_object({}) do |matcher, memo| memo[matcher.class.symbol] = matcher.match() end return match_data if match_data.values.none? { |value| Util.blank?(value) } nil end |