Class Net::YAIL::MessageParser
In: lib/net/yail/message_parser.rb
Parent: Object

This is my lame attempt to convert the BNF-style grammar from RFC 1459 into useable ruby regexes. The hope here is that one can effectively match an incoming message with high accuracy. Usage:

    line = ':Nerdmaster!jeremy@nerdbucket.com PRIVMSG Nerdminion :Do my bidding!!'
    message = Net::YAIL::MessageParser.new(line)
    # hash now has all kinds of useful pieces of the incoming message:
    puts line.nick        # "Nerdmaster"
    puts line.user        # "jeremy"
    puts line.host        # "nerdbucket.com"
    puts line.prefix      # "Nerdmaster!jeremy@nerdbucket.com"
    puts line.command     # "PRIVMSG"
    puts line.params      # ["Nerdminion", "Do my bidding!!"]

Methods

new  

Constants

USER = /\S+?/   Note that all regexes are non-greedy. I‘m scared of greedy regexes, sirs.
NICK = /[\w\d\\|`'^{}\]\[-]+?/   RFC suggested that a nick had to start with a letter, but that seems to not be the case.
HOST = /\S+?/
SERVERNAME = /\S+?/
PREFIX = /((#{NICK})!(#{USER})@(#{HOST})|#{SERVERNAME})/   This is automatically grouped for ease of use in the parsing. Group 1 is the full prefix; 2, 3, and 4 are nick/user/host; 1 is also servername if there was no match to populate 2, 3, and 4.
COMMAND = /(\w+|\d{3})/
TRAILING = /\:\S*?/
MIDDLE = /(?: +([^ :]\S*))/
MESSAGE = /^(?::#{PREFIX} +)?#{COMMAND}(.*)$/

Attributes

command  [R] 
host  [R] 
nick  [R] 
params  [R] 
prefix  [R] 
servername  [R] 
user  [R] 

Public Class methods

[Validate]