Sha256: 8c3f04b1314408f3984f5ff0cc46f2936272df881680528d2765167de96e4a4c

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require_relative File.join('..', 'matchers_base') unless
  defined?(::Matchi::MatchersBase)

module Matchi
  module Matchers
    # **Regular expressions** matcher.
    module Match
      # The matcher.
      class Matcher
        include MatchersBase

        # Initialize the matcher with an instance of Regexp.
        #
        # @example Username matcher.
        #   Matchi::Matchers::Match::Matcher.new(/^[a-z0-9_-]{3,16}$/)
        #
        # @param expected [#match] A regular expression.
        def initialize(expected)
          @expected = expected
        end

        # Boolean comparison between the actual value and the expected value.
        #
        # @example Is it matching /^foo$/ regex?
        #   match = Matchi::Matchers::Match::Matcher.new(/^foo$/)
        #   match.matches? { 'foo' } # => true
        #
        # @yieldreturn [#object_id] the actual value to compare to the expected
        #   one.
        #
        # @return [Boolean] Comparison between actual and expected values.
        def matches?
          @expected.match(yield).nil?.equal?(false)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
matchi-1.0.2 lib/matchi/matchers/match.rb
matchi-1.0.1 lib/matchi/matchers/match.rb
matchi-1.0.0 lib/matchi/matchers/match.rb