class Tjplurk::Robot
Public Class Methods
new(topics)
click to toggle source
# File lib/tjplurk/robot.rb, line 3 def initialize topics @topics = topics end
Public Instance Methods
respond(input)
click to toggle source
# File lib/tjplurk/robot.rb, line 7 def respond input if matched = @topics.each{|topic| topic.pattern = Regexp.new(topic.pattern) if topic.pattern.is_a? String}.select{|topic| topic.pattern.match(input) }.sample response = matched.responses.sample.content match_data = matched.pattern.match(input) response.gsub(/\\(\d+)/){|s| match_data[$1.to_i]} end end