Sha256: 3edfb201dc2464a9513a2068979f0a9cd2c54c1ae28027a5799d107c6e8498f1

Contents?: true

Size: 636 Bytes

Versions: 2

Compression:

Stored size: 636 Bytes

Contents

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
matchi-0.0.5 lib/matchi/match.rb
matchi-0.0.4 lib/matchi/match.rb