Class: Qo::Matchers::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/qo/matchers/matcher.rb

Overview

Matcher used to determine whether a value matches a certain set of conditions

Author:

  • baweaver

Since:

  • 1.0.0

Instance Method Summary collapse

Constructor Details

#initialize(type, array_matchers = [], keyword_matchers = {}) ⇒ Qo::Matchers::Matcher

Creates a new matcher

Parameters:

  • type (String)

    Type of the matcher: any, all, or none. Used to determine how a match is determined

  • array_matchers (defaults to: [])

    = [] [Array[Any]] Conditions given as an array

  • keyword_matchers (defaults to: {})

    = {} [Hash[Any, Any]] Conditions given as keywords

Since:

  • 1.0.0



23
24
25
26
27
# File 'lib/qo/matchers/matcher.rb', line 23

def initialize(type, array_matchers = [], keyword_matchers = {})
  @type = type
  @array_matchers = array_matchers
  @keyword_matchers = keyword_matchers
end

Instance Method Details

#call(target) ⇒ Boolean Also known as: ===, [], match?

Calls the matcher on a given target value

Parameters:

  • target (Any)

    Target to match against

Returns:

  • (Boolean)

    Whether or not the target matched

Since:

  • 1.0.0



43
44
45
# File 'lib/qo/matchers/matcher.rb', line 43

def call(target)
  combined_check(array_call(target), keyword_call(target))
end

#to_procProc[Any] => Boolean

Proc-ified version of call

Returns:

  • (Proc[Any] => Boolean)

Since:

  • 1.0.0



32
33
34
# File 'lib/qo/matchers/matcher.rb', line 32

def to_proc
  -> target { self.call(target) }
end