Class: Qo::Matchers::ArrayMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Qo::Matchers::ArrayMatcher
- Defined in:
- lib/qo/matchers/array_matcher.rb
Overview
An Array Matcher is a matcher that uses only varargs to define a sequence of matches to perform against either an object or another Array.
In the case of an Array matching against an Array it will compare via index.
In the case of an Array matching against an Object, it will match each provided matcher against the object.
All variants present in the BaseMatcher are present here, including ‘and’, ‘not’, and ‘or’.
Instance Method Summary collapse
-
#call(target) ⇒ Boolean
Invocation for the match sequence.
-
#to_proc ⇒ Proc[Any]
Used to match against a matcher made from an Array, like:.
Methods inherited from BaseMatcher
Constructor Details
This class inherits a constructor from Qo::Matchers::BaseMatcher
Instance Method Details
#call(target) ⇒ Boolean
Invocation for the match sequence. Will determine the target and applicable matchers to run against it.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/qo/matchers/array_matcher.rb', line 36 def call(target) return true if @array_matchers == target if target.is_a?(::Array) match_with(@array_matchers.each_with_index) { |matcher, i| match_value?(target[i], matcher) } else match_with(@array_matchers) { |matcher| match_value?(target, matcher) } end end |
#to_proc ⇒ Proc[Any]
Used to match against a matcher made from an Array, like:
Qo['Foo', 'Bar']
26 27 28 |
# File 'lib/qo/matchers/array_matcher.rb', line 26 def to_proc Proc.new { |target| self.call(target) } end |