Class: ChatBot::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/chatbot/main.rb

Instance Method Summary collapse

Constructor Details

#initializeMain

Returns a new instance of Main.



3
4
5
# File 'lib/chatbot/main.rb', line 3

def initialize
  @rule = {}
end

Instance Method Details

#command(command, &block) ⇒ Object



28
29
30
# File 'lib/chatbot/main.rb', line 28

def command(command, &block)
  @rule[command] = block
end

#configurationObject



6
7
8
# File 'lib/chatbot/main.rb', line 6

def configuration
  @configuration ||= Configuration.new
end

#configure {|configuration| ... } ⇒ Object

Yields:



10
11
12
# File 'lib/chatbot/main.rb', line 10

def configure
  yield(configuration) if block_given?
end

#processMessage(rawMessage) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/chatbot/main.rb', line 14

def processMessage(rawMessage)
  message = GroupMeParser.parse(rawMessage)
  if message.is_command?
    rule = find_rule(message.command)
    unless rule.nil?
      outmessage = rule.call(message)
      unless outmessage.nil?
        send_message(outmessage)
      end
    end
  end
  return message
end