Class: Jekyll::RpLogs::WeechatParser

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

Overview

Parses logs in the default format of [Weechat](weechat.org/)

Constant Summary collapse

FORMAT_STR =

Add this class to the parsing dictionary

"weechat"
DATE_REGEXP =

Date is repeated in each type of message

/(?<timestamp>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)/
TIMESTAMP_FORMAT =
"%Y-%m-%d %H:%M:%S"
JUNK =

Regular expressions for matching each type of line

/#{DATE_REGEXP}\t<?-->?\t.*$/
EMOTE =
/^#{FLAGS}#{DATE_REGEXP}\t \*\t#{NICK}\s+(?<msg>[^\n]*)$/
TEXT =
/^#{FLAGS}#{DATE_REGEXP}\t#{MODE}#{NICK}\t(?<msg>[^\n]*)$/

Constants inherited from Parser

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

Class Method Summary collapse

Class Method Details

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jekyll/rp_logs/parse_weechat.rb', line 19

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