ruby - bob (2)
This commit is contained in:
parent
b430f35082
commit
113fa6679b
@ -1,18 +1,54 @@
|
||||
# class Bob
|
||||
class Bob
|
||||
def self.hey(remark)
|
||||
remark.gsub!(/[[:space:]]+/, '')
|
||||
if remark == ''
|
||||
response = Response.new(remark)
|
||||
if silence?(remark)
|
||||
response.silence
|
||||
elsif shout?(remark)
|
||||
response.shouted_at
|
||||
elsif question?(remark)
|
||||
response.question
|
||||
else
|
||||
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!'
|
||||
elsif remark.upcase == remark and remark =~ /[A-Za-z]+/
|
||||
if remark[-1] == '?'
|
||||
end
|
||||
|
||||
def shouted_at
|
||||
if @remark.end_with?('?')
|
||||
"Calm down, I know what I'm doing!"
|
||||
else
|
||||
'Whoa, chill out!'
|
||||
end
|
||||
elsif remark[-1] == '?'
|
||||
end
|
||||
|
||||
def question
|
||||
'Sure.'
|
||||
else
|
||||
end
|
||||
|
||||
def default
|
||||
'Whatever.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user