Class: Cattify

Inherits:
Object
  • Object
show all
Defined in:
lib/cattify.rb,
lib/cattify/version.rb

Constant Summary collapse

ADJECTIVES =
%w(purry mewly meowwwer).freeze
VERSION =
"1.0.1"

Instance Method Summary collapse

Constructor Details

#initializeCattify

Returns a new instance of Cattify.



7
8
9
# File 'lib/cattify.rb', line 7

def initialize
  @tagger = EngTagger.new
end

Instance Method Details

#adjective(i) ⇒ Object



32
33
34
# File 'lib/cattify.rb', line 32

def adjective(i)
  ADJECTIVES[i % ADJECTIVES.size]
end

#process(str) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cattify.rb', line 11

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 "meow".
  phrases << 'meow.'

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