Sha256: 9ed7c8b880fb2cf09b514435b45af629711fb3d77b37b7b8dbc0c1f0b9e9fca7

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

require 'rflow/components/irc/extensions'
require 'rflow/components/irc/client'

# RFlow classes.
class RFlow
  # RFlow component classes.
  module Components
    # IRC RFlow component classes.
    module IRC
      # Load the schemas
      # @!visibility private
      SCHEMA_DIRECTORY = ::File.expand_path(::File.join(::File.dirname(__FILE__), '..', '..', '..', 'schema'))

      # @!visibility private
      SCHEMA_FILES = {
        'irc_message.avsc'  => 'RFlow::Message::Data::IRC::Message',
      }

      SCHEMA_FILES.each do |file_name, data_type_name|
        schema_string = ::File.read(::File.join(SCHEMA_DIRECTORY, file_name))
        RFlow::Configuration.add_available_data_type data_type_name, 'avro', schema_string
      end

      # Load the data extensions
      RFlow::Configuration.add_available_data_extension('RFlow::Message::Data::IRC::Message',
                                                        RFlow::Components::IRC::Extensions::IRCMessageExtension)

      # Some useful IRC parsing methods
      # @!visibility private
      IRC_LINE_REGEX = /^(?::(\S+) )?(\S+)(?: (.+))?$/
      # @!visibility private
      IRC_PREFIX_REGEX = /^([^!]+)(?:!([^@]+))?(?:@(.*)+)?$/

      # @!visibility private
      def self.parse_irc_line(line)
        match = IRC_LINE_REGEX.match(line)
        unless match
          RFlow.logger.error "Error parsing IRC line '#{line}'"
          return
        end

        prefix, cmd, param_string = match[1..3]

        param_string, trailing_param = param_string.split(' :', 1)
        params = param_string.split(' ')
        params << trailing_param if trailing_param

        [prefix, cmd, params]
      end

      # @!visibility private
      def self.parse_irc_prefix(prefix)
        match = IRC_PREFIX_REGEX.match(prefix)
        unless match
          RFlow.logger.error "Error parsing IRC prefix '#{prefix}'"
          return
        end

        # nick/server, user, host
        match[1..3]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rflow-components-irc-1.1.1 lib/rflow/components/irc.rb