Sha256: 380c1ca457883a37dfa84d356cc9cab0e8e4c189eca900a6d83111c5f61c77e5

Contents?: true

Size: 744 Bytes

Versions: 2

Compression:

Stored size: 744 Bytes

Contents

class LooseTightDictionary
  # Identities take effect when needle and haystack both match a regexp
  # Then the captured part of the regexp has to match exactly
  class Identity
    include ExtractRegexp
    
    attr_reader :regexp
    
    def initialize(regexp_or_str)
      @regexp = extract_regexp regexp_or_str
    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

2 entries across 2 versions & 1 rubygems

Version Path
loose_tight_dictionary-0.1.1 lib/loose_tight_dictionary/identity.rb
loose_tight_dictionary-0.1.0 lib/loose_tight_dictionary/identity.rb