Class: Matchi::Matcher::Match

Inherits:
Base
  • Object
show all
Defined in:
lib/matchi/matcher/match.rb

Overview

**Regular expressions** matcher.

Instance Attribute Summary

Attributes inherited from Base

#expected

Instance Method Summary collapse

Methods inherited from Base

#inspect, #to_s, to_sym

Constructor Details

#initialize(expected) ⇒ Match

Initialize the matcher with an instance of Regexp.

Examples:

Username matcher.

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

Parameters:

  • expected (#match)

    A regular expression.



15
16
17
# File 'lib/matchi/matcher/match.rb', line 15

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::Matcher::Match.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.



29
30
31
# File 'lib/matchi/matcher/match.rb', line 29

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