Module: Soulheart::Helpers

Included in:
Base, Server
Defined in:
lib/soulheart/helpers.rb

Instance Method Summary collapse

Instance Method Details

#normalize(str) ⇒ Object



4
5
6
7
# File 'lib/soulheart/helpers.rb', line 4

def normalize(str)
  # Letter, Mark, Number, Connector_Punctuation (Chinese, Japanese, etc.)
  str.downcase.gsub(/[^\p{Word}\ ]/i, '').strip
end

#prefixes_for_phrase(phrase) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/soulheart/helpers.rb', line 9

def prefixes_for_phrase(phrase)
  words = normalize(phrase).split(' ').reject do |w|
    Soulheart.stop_words.include?(w)
  end
  words.map do |w|
    (0..(w.length - 1)).map { |l| w[0..l] }
  end.flatten.uniq
end