Sha256: 7e98fd8ba25da04179707241179f596d434663a9eeab08b0b955a498a8f29bdd

Contents?: true

Size: 519 Bytes

Versions: 5

Compression:

Stored size: 519 Bytes

Contents

class FuzzyMatch
  class Rule
    # A normalizer just strips a string down to its core
    class Normalizer < Rule
      # A normalizer applies when its regexp matches and captures a new (shorter) string
      def apply?(str)
        !!(regexp.match(str))
      end
    
      # The result of applying a normalizer is just all the captures put together.
      def apply(str)
        if match_data = regexp.match(str)
          match_data.captures.join
        else
          str
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fuzzy_match-1.5.0 lib/fuzzy_match/rule/normalizer.rb
fuzzy_match-1.4.1 lib/fuzzy_match/rule/normalizer.rb
fuzzy_match-1.4.0 lib/fuzzy_match/rule/normalizer.rb
fuzzy_match-1.3.3 lib/fuzzy_match/rule/normalizer.rb
fuzzy_match-1.3.2 lib/fuzzy_match/rule/normalizer.rb