Sha256: 45b7db5cfd2779ea6a55827c64c61670f9e56ab743081a66eeeac6c679f1c4e7

Contents?: true

Size: 832 Bytes

Versions: 7

Compression:

Stored size: 832 Bytes

Contents

class LooseTightDictionary
  # Wrappers are the tokens that are passed around when doing scoring and optimizing.
  class Wrapper #:nodoc: all
    attr_reader :parent
    attr_reader :record
    attr_reader :reader

    def initialize(attrs = {})
      attrs.each do |k, v|
        instance_variable_set "@#{k}", v
      end
    end

    def inspect
      "#<Wrapper to_str=#{to_str} variants=#{variants.length}>"
    end

    def to_str
      @to_str ||= reader ? reader.call(record) : record.to_s
    end

    alias :to_s :to_str

    def similarity(other)
      Similarity.new self, other
    end

    def variants
      @variants ||= parent.tighteners.inject([ to_str ]) do |memo, tightener|
        if tightener.apply? to_str
          memo.push tightener.apply(to_str)
        end
        memo
      end.uniq
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
loose_tight_dictionary-1.0.0 lib/loose_tight_dictionary/wrapper.rb
loose_tight_dictionary-0.2.3 lib/loose_tight_dictionary/wrapper.rb
loose_tight_dictionary-0.2.2 lib/loose_tight_dictionary/wrapper.rb
loose_tight_dictionary-0.2.1 lib/loose_tight_dictionary/wrapper.rb
loose_tight_dictionary-0.2.0 lib/loose_tight_dictionary/wrapper.rb
loose_tight_dictionary-0.1.1 lib/loose_tight_dictionary/wrapper.rb
loose_tight_dictionary-0.1.0 lib/loose_tight_dictionary/wrapper.rb