Class: Matchi::Matchers::Match::Matcher

Inherits:
Object
  • Object
show all
Includes:
Matchi::MatchersBase
Defined in:
lib/matchi/matchers/match.rb

Overview

The matcher.

Instance Method Summary collapse

Methods included from Matchi::MatchersBase

#to_h, #to_s

Constructor Details

#initialize(expected) ⇒ Matcher

Initialize the matcher with an instance of Regexp.

Examples:

Username matcher.

Matchi::Matchers::Match::Matcher.new(/^[a-z0-9_-]{3,16}$/)

Parameters:

  • expected (#match)

    A regular expression.



20
21
22
# File 'lib/matchi/matchers/match.rb', line 20

def initialize(expected)
  @expected = expected
end

Instance Method Details

#matches?Boolean

Boolean comparison between the actual value and the expected value.

Examples:

Is it matching /^foo$/ regex?

match = Matchi::Matchers::Match::Matcher.new(/^foo$/)
match.matches? { 'foo' } # => true

Yield Returns:

  • (#object_id)

    The actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.



34
35
36
# File 'lib/matchi/matchers/match.rb', line 34

def matches?(*, **)
  @expected.match(yield).nil?.equal?(false)
end