Sha256: 49913641493ef74f640766a55a0ffc51b1ab2b7bbdb3ebabc77cff0084fb03eb
Contents?: true
Size: 1.61 KB
Versions: 3
Compression:
Stored size: 1.61 KB
Contents
class FuzzyMatch # Wrappers are the tokens that are passed around when doing scoring and optimizing. class Wrapper #:nodoc: all # "Foo's" is one word # "North-west" is just one word # "Bolivia," is just Bolivia WORD_BOUNDARY = %r{\W*(?:\s+|$)} attr_reader :fuzzy_match attr_reader :record attr_reader :literal attr_reader :rendered def initialize(fuzzy_match, record, literal = false) @fuzzy_match = fuzzy_match @record = record @literal = literal end def inspect "#<FuzzyMatch::Wrapper render=#{render.inspect} variants=#{variants.length}>" end def read fuzzy_match.read unless literal end def render @render ||= begin memo = case read when ::Proc read.call record when ::Symbol if record.respond_to?(read) record.send read else record[read] end when ::NilClass record else record[read] end.to_s.dup fuzzy_match.stop_words.each do |stop_word| stop_word.apply! memo end memo.strip! @render = memo.freeze end end alias :to_str :render def words @words ||= render.downcase.split(WORD_BOUNDARY) end def similarity(other) Similarity.new self, other end def variants @variants ||= begin fuzzy_match.normalizers.inject([ render ]) do |memo, normalizer| if normalizer.apply? render memo << normalizer.apply(render) end memo end.uniq end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fuzzy_match-1.5.0 | lib/fuzzy_match/wrapper.rb |
fuzzy_match-1.4.1 | lib/fuzzy_match/wrapper.rb |
fuzzy_match-1.4.0 | lib/fuzzy_match/wrapper.rb |