Module: Soulheart::Helpers

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

Instance Method Summary collapse

Instance Method Details

#normalize(str) ⇒ Object



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

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

#prefixes_for_phrase(phrase) ⇒ Object



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

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