Class: Jekyll::RpLogs::MIRCParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/jekyll/rp_logs/parsers/mirc.rb

Constant Summary collapse

FORMAT_STR =

Add this class to the parsing dictionary

"MIRC"
DATE_REGEXP =

Remember to change this for your date format For example, this regex is for, mm dd yy or 06 14 15 The default mirc date format is HH:nn

/(?<timestamp>\d\d \d\d \d\d\[\d\d:\d\d\])/
TIMESTAMP_FORMAT =

Also make sure to change this - pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html If you are using the default mirc format, this should be “[%H:%M]”

"%m %d %y[%H:%M]"
USER_AT_HOST =

Crappy but works

/\(\w+@[^)]+\)/
MSG =
/(?<msg>[^\n]*)/
JUNK =

The ()?((?=d4)(dd))? bit of code is to remove the  and two random numbers in front of lines. This assumes that you have a two digit date code stating your time stamp.

/()?((?=\d{4})(\d\d))?#{DATE_REGEXP} \* #{MODE}#{NICK} (sets mode:|is now known as|(#{USER_AT_HOST} (has joined|Quit|has left))).*$/
EMOTE =
/^#{FLAGS}()?((?=\d{4})(\d\d))?#{DATE_REGEXP}\s\*\s#{MODE}#{NICK}\s+#{MSG}$/
TEXT =
/^#{FLAGS}()?((?=\d{4})(\d\d))?#{DATE_REGEXP}\s<#{MODE}#{NICK}>\s#{MSG}$/

Constants inherited from Parser

Parser::FLAGS, Parser::MODE, Parser::NICK

Class Method Summary collapse

Class Method Details

.parse_line(line, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jekyll/rp_logs/parsers/mirc.rb', line 25

def self.parse_line(line, options = {})
  case line
  when JUNK
    return nil
  when EMOTE
    type = :rp
  when TEXT
    type = :ooc
    mode = $LAST_MATCH_INFO[:mode]
    mode = " " if mode == ""
  else
    # Only put text and emotes in the log
    return nil
  end
  date = DateTime.strptime($LAST_MATCH_INFO[:timestamp], TIMESTAMP_FORMAT)
  LogLine.new(
    date,
    options,
    sender: $LAST_MATCH_INFO[:nick],
    contents: $LAST_MATCH_INFO[:msg],
    flags: $LAST_MATCH_INFO[:flags],
    type: type,
    mode: mode
  )
end