Class: FuzzyMatch::Rule::Normalizer

Inherits:
FuzzyMatch::Rule show all
Defined in:
lib/fuzzy_match/rule/normalizer.rb

Overview

A normalizer just strips a string down to its core

Instance Attribute Summary

Attributes inherited from FuzzyMatch::Rule

#regexp

Instance Method Summary collapse

Methods inherited from FuzzyMatch::Rule

#==, #initialize

Constructor Details

This class inherits a constructor from FuzzyMatch::Rule

Instance Method Details

#apply(str) ⇒ Object

The result of applying a normalizer is just all the captures put together.



11
12
13
14
15
16
17
# File 'lib/fuzzy_match/rule/normalizer.rb', line 11

def apply(str)
  if match_data = regexp.match(str)
    match_data.captures.join
  else
    str
  end
end

#apply?(str) ⇒ Boolean

A normalizer applies when its regexp matches and captures a new (shorter) string

Returns:

  • (Boolean)


6
7
8
# File 'lib/fuzzy_match/rule/normalizer.rb', line 6

def apply?(str)
  !!(regexp.match(str))
end