Sha256: 49d034dbd95c3d7ce6b7559d86a44f1cfab21674bbc90f2e924b6a067d507757
Contents?: true
Size: 864 Bytes
Versions: 4
Compression:
Stored size: 864 Bytes
Contents
module Phonetic # Base class for phonetic algorithms. class Algorithm # Generic method for encoding single word. Override it in your algorithm class. # @param [String] word the word to encode # @param [Hash] options the options for the algorithm # @return [String] the word def self.encode_word(word, options = {}) word end # Generic method for encoding string. # Splits string by words and encodes it with {Algorithm.encode_word}. # # @param [String] str the string to encode. # @param [Hash] options the options for algorithm. # @return [String] the space separated codes of words from input string. def self.encode(str, options = {}) str.scan(/\p{Word}+/).map do |word| encode_word(word, options) end.compact.reject(&:empty?).join(' ') end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
phonetic-1.2.0 | lib/phonetic/algorithm.rb |
phonetic-1.1.0 | lib/phonetic/algorithm.rb |
phonetic-1.0.1 | lib/phonetic/algorithm.rb |
phonetic-1.0.0 | lib/phonetic/algorithm.rb |