Module: DavidDowncase

Defined in:
lib/david_downcase.rb,
lib/david_downcase/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

ADJECTIVES =
%w(so such very much many).freeze
VERSION =
"0.1.2"

Instance Method Summary collapse

Instance Method Details

#initializeObject



10
11
12
# File 'lib/david_downcase.rb', line 10

def initialize
  @tagger = EngTagger.new
end

#process(str) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/david_downcase.rb', line 14

def process(str)
  # Convert input to lowercase.
  str = str.downcase

  # Extract nouns, prefixing each with one of the
  # above adjectives into sentences of 2 words.
  tagged_str = @tagger.add_tags(str)
  phrases = @tagger.get_nouns(tagged_str).keys
  phrases = phrases.each_with_index.map do |phrase, i|
    "#{adjective(i)} #{phrase}."
  end

  # End every input with "wow".
  phrases << 'wow.'

  # Return a string, separating each sentence
  # with a space.
  phrases.join(' ')
end