diff --git a/ruby/bob/bob.rb b/ruby/bob/bob.rb index 70ea19d..621b81e 100644 --- a/ruby/bob/bob.rb +++ b/ruby/bob/bob.rb @@ -1,18 +1,54 @@ +# class Bob class Bob def self.hey(remark) - remark.gsub!(/[[:space:]]+/, '') - if remark == '' - 'Fine. Be that way!' - elsif remark.upcase == remark and remark =~ /[A-Za-z]+/ - if remark[-1] == '?' - "Calm down, I know what I'm doing!" - else - 'Whoa, chill out!' - end - elsif remark[-1] == '?' - 'Sure.' + response = Response.new(remark) + if silence?(remark) + response.silence + elsif shout?(remark) + response.shouted_at + elsif question?(remark) + response.question else - 'Whatever.' + response.default end end + + def self.silence?(remark) + remark.strip.empty? + end + + def self.shout?(remark) + remark.upcase == remark && remark =~ /[A-Za-z]+/ + end + + def self.question?(remark) + remark.strip.end_with?('?') + end +end + +# Response +class Response + def initialize(remark) + @remark = remark.strip + end + + def silence + 'Fine. Be that way!' + end + + def shouted_at + if @remark.end_with?('?') + "Calm down, I know what I'm doing!" + else + 'Whoa, chill out!' + end + end + + def question + 'Sure.' + end + + def default + 'Whatever.' + end end