Sha256: 2635c83292b75584d797c519abf36a8c198a8646581f04c7d7a6a85052cc482f

Contents?: true

Size: 698 Bytes

Versions: 3

Compression:

Stored size: 698 Bytes

Contents

class FuzzyMatch
  # Identities take effect when needle and haystack both match a regexp
  # Then the captured part of the regexp has to match exactly
  class Identity
    attr_reader :regexp
    
    def initialize(regexp_or_str)
      @regexp = regexp_or_str.to_regexp
    end
    
    # Two strings are "identical" if they both match this identity and the captures are equal.
    #
    # Only returns true/false if both strings match the regexp.
    # Otherwise returns nil.
    def identical?(str1, str2)
      if str1_match_data = regexp.match(str1) and match_data = regexp.match(str2)
        str1_match_data.captures == match_data.captures
      else
        nil
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fuzzy_match-1.1.1 lib/fuzzy_match/identity.rb
fuzzy_match-1.1.0 lib/fuzzy_match/identity.rb
fuzzy_match-1.0.5 lib/fuzzy_match/identity.rb