Class: Qo::Matchers::BaseMatcher
- Inherits:
-
Object
- Object
- Qo::Matchers::BaseMatcher
- Defined in:
- lib/qo/matchers/base_matcher.rb
Overview
Base instance of matcher which is meant to take in either Array style or Keyword style arguments to run a match against various datatypes.
Will delegate responsibilities to either Array or Hash style matchers if invoked directly.
Direct Known Subclasses
Instance Method Summary collapse
-
#call(target) ⇒ Boolean
(also: #===, #[])
You can directly call a matcher as well, much like a Proc, using one of call, ===, or [].
-
#initialize(type, *array_matchers, **keyword_matchers) ⇒ BaseMatcher
constructor
A new instance of BaseMatcher.
-
#to_proc ⇒ Proc[Any]
Converts a Matcher to a proc for use in querying, such as:.
Constructor Details
#initialize(type, *array_matchers, **keyword_matchers) ⇒ BaseMatcher
Returns a new instance of BaseMatcher
25 26 27 28 29 |
# File 'lib/qo/matchers/base_matcher.rb', line 25 def initialize(type, *array_matchers, **keyword_matchers) @array_matchers = array_matchers @keyword_matchers = keyword_matchers @type = type end |
Instance Method Details
#call(target) ⇒ Boolean Also known as: ===, []
You can directly call a matcher as well, much like a Proc, using one of call, ===, or []
48 49 50 |
# File 'lib/qo/matchers/base_matcher.rb', line 48 def call(target) self.to_proc.call(target) end |
#to_proc ⇒ Proc[Any]
Converts a Matcher to a proc for use in querying, such as:
data.select(&Qo[...])
36 37 38 39 40 |
# File 'lib/qo/matchers/base_matcher.rb', line 36 def to_proc @array_matchers.empty? ? Qo::Matchers::HashMatcher.new(@type, **@keyword_matchers).to_proc : Qo::Matchers::ArrayMatcher.new(@type, *@array_matchers).to_proc end |