Sha256: ddf5f667688261535be5658dae352d8a6e8e39bb0ed6d4e06db6343951938d11

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Picky

  # encoding: utf-8
  #
  module Generators

    module Similarity

      # It's actually a combination of double metaphone
      # and Levenshtein.
      #
      # It uses the double metaphone to get similar words
      # and ranks them using the levenshtein.
      #
      class Phonetic < Strategy

        attr_reader :amount

        #
        #
        def initialize amount = 10
          check_gem

          raise "In Picky 2.0+, the Similarity::Phonetic has been renamed to Similarity::DoubleMetaphone. Please use that one. Thanks!" if self.class == Phonetic
          @amount = amount
        end

        # Tries to require the text gem.
        #
        def check_gem # :nodoc:
          require 'text'
        rescue LoadError
          warn_gem_missing 'text', 'a phonetic Similarity'
          exit 1
        end

        # Sorts the index values in place.
        #
        # Not used currently.
        #
        def prioritize! ary, code
          ary.sort_by_levenshtein! code
          ary.slice! amount, ary.size # THINK size is not perfectly correct, but anyway
        end

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
picky-4.0.0pre5 lib/picky/generators/similarity/phonetic.rb
picky-4.0.0pre3 lib/picky/generators/similarity/phonetic.rb