Class: Project::Caveman

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

Constant Summary collapse

SUBSTITUTES =
{
  "I" => "me",
  "am " => "",
  "don't" => "no"
}

Instance Method Summary collapse

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
# File 'lib/caveman.rb', line 26

def call
  greet_user
  loop do
    take_input
    break if @input == 'exit'
    puts sub_string
  end
end

#greet_userObject



18
19
20
# File 'lib/caveman.rb', line 18

def greet_user
  puts "you talk. me repeat. say exit, me quit."
end

#sub_stringObject



12
13
14
15
16
# File 'lib/caveman.rb', line 12

def sub_string
  new_string = @input
  SUBSTITUTES.each {|word, replacement| new_string = new_string.gsub(/\b#{word}\b/, replacement)}
  "grunt...#{new_string.downcase}"
end

#take_inputObject



22
23
24
# File 'lib/caveman.rb', line 22

def take_input
  @input = gets.strip
end