Class: HenriettaPussycat::Meow

Inherits:
Object
  • Object
show all
Defined in:
lib/henrietta_pussycat/meow.rb

Class Method Summary collapse

Class Method Details

.classic_meow_insert(sentence, word_array = ['beautiful', 'telephone', 'Mr. Rogers']) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/henrietta_pussycat/meow.rb', line 10

def self.classic_meow_insert(sentence, word_array=['beautiful', 'telephone', 'Mr. Rogers'])
  if word_array.size > 0
    match_word = word_array.pop
    chunks = sentence.split(/\b(#{match_word})\b/i)
    chunks.map! do |chunk|
      if chunk.match(/\b(#{match_word})\b/i)
        chunk
      else
        classic_meow_insert(chunk, word_array.dup)
      end
    end
    chunks.join("")
  else
    sentence.gsub(/\w+\'*\w*/, "meow")
  end
end

.random_meow_insert(sentence) ⇒ Object



3
4
5
6
7
8
# File 'lib/henrietta_pussycat/meow.rb', line 3

def self.random_meow_insert(sentence)
  pick_string = sentence.gsub(/[^\w]/i, "")
  index = rand(pick_string.length - 1)
  substitute_character = pick_string[index..index]
  sentence.gsub(/\b\w*#{substitute_character}\w*\b/i, "meow")
end