Class: MoonBot::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/MoonBot/parser.rb

Class Method Summary collapse

Class Method Details

.parse(data) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/MoonBot/parser.rb', line 3

def self.parse data
  message = {}
  # if not empty
  if data.scan(/^:/).empty?
    body = data.split ' '
    message[:command] = body.shift
    message[:args]    = body
  else
    separated = data.split ':'
    body  = separated[1].split ' '
    message[:prefix]  = body.shift
    message[:command] = body.shift
    message[:params]  = body.shift
    2.times { separated.shift }
    message[:trailing] = separated.join(":")
  end
  message
rescue
  nil
end