Sha256: da019118883c5b7c3681b8034b76c97ca3c47cb6a3d01b923b384639f67c1d25

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

module Jekyll
  module RpLogs
    ##
    # Parses logs in the default format of [Weechat](https://weechat.org/)
    class WeechatParser < RpLogs::Parser
      # Add this class to the parsing dictionary
      FORMAT_STR = "weechat"
      RpLogGenerator.add self

      # Date is repeated in each type of message
      DATE_REGEXP = /(?<timestamp>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)/
      TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S"

      # Regular expressions for matching each type of line
      JUNK =  /#{DATE_REGEXP}\t<?-->?\t.*$/
      EMOTE = /^#{FLAGS}#{DATE_REGEXP}\t \*\t#{NICK}\s+(?<msg>[^\n]*)$/
      TEXT  = /^#{FLAGS}#{DATE_REGEXP}\t#{MODE}#{NICK}\t(?<msg>[^\n]*)$/

      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jekyll-rp_logs-0.5.0 lib/jekyll/rp_logs/parsers/weechat.rb
jekyll-rp_logs-0.4.0 lib/jekyll/rp_logs/parse_weechat.rb
jekyll-rp_logs-0.3.1 lib/jekyll/rp_logs/parse_weechat.rb
jekyll-rp_logs-0.3.0 lib/jekyll/rp_logs/parse_weechat.rb
jekyll-rp_logs-0.2.1 lib/jekyll/rp_logs/parse_weechat.rb
jekyll-rp_logs-0.2.0 lib/jekyll/rp_logs/parse_weechat.rb