class OPSA::Language
Public Class Methods
new()
click to toggle source
# File lib/opsa/language.rb, line 4 def initialize @actions = Hash.new nil end
Public Instance Methods
input(text)
click to toggle source
# File lib/opsa/language.rb, line 23 def input(text) @actions.each do |regex, action| if _match = text.match(regex) args = _match.captures if args.size > 0 return action.call(*args) else return action.call(text) end else next end end return nil end
respond_to(regex, &action)
click to toggle source
Define language
Example:
lang.respond_to Regexp.new('^say_hello (.+)') do |match| puts "> Hello, #{match}!" end
Arguments:
regex: Regexp action: Block
# File lib/opsa/language.rb, line 19 def respond_to(regex, &action) @actions[regex] ||= action end