Class: Tjplurk::Robot

Inherits:
Object
  • Object
show all
Defined in:
lib/tjplurk/robot.rb,
lib/tjplurk/robot/topic.rb,
lib/tjplurk/robot/response.rb

Defined Under Namespace

Classes: Response, Topic

Instance Method Summary collapse

Constructor Details

#initialize(topics) ⇒ Robot

Returns a new instance of Robot.



3
4
5
# File 'lib/tjplurk/robot.rb', line 3

def initialize topics
  @topics = topics
end

Instance Method Details

#respond(input) ⇒ Object



7
8
9
10
11
12
# File 'lib/tjplurk/robot.rb', line 7

def respond input
  if matched = @topics.select{|topic| topic.pattern.match(input) }.sample
    response = matched.responses.sample.content
    input.gsub!(matched.pattern, response)
  end
end