class SSCBot::ChatLog::Message

The base class of all parsed messages from a chat log file.

@author Jonathan Bradley Whited @since 0.1.0

Constants

TYPES

Valid types of messages.

You can add your own custom type(s) that you parse manually:

SSCBot::ChatLog::Message.add_type(:custom)

Attributes

line[R]
type[R]

Public Class Methods

add_type(type) click to toggle source

Adds type to the list of valid {TYPES} and creates a boolean method for it ending with a +?+.

@param type [Symbol,String] the new type to add

# File lib/ssc.bot/chat_log/message.rb, line 30
def self.add_type(type)
  type = type.to_sym

  return if TYPES.include?(type)

  TYPES.add(type)

  name = type.to_s.sub('?','q_')

  define_method(:"type_#{name}?") do
    return @type == type
  end
end
new(line,type:) click to toggle source

@param line [String] the raw (unparsed) line from the file @param type [Symbol] what type of message this is; must be one of {TYPES}

# File lib/ssc.bot/chat_log/message.rb, line 76
def initialize(line,type:)
  type = type.to_sym

  raise ArgumentError,"invalid line{#{line.inspect}}" if line.nil?
  raise ArgumentError,"invalid type{#{type.inspect}}" if !self.class.valid_type?(type)

  @line = line
  @type = type
end
valid_type?(type) click to toggle source

@param type [Symbol] the type to check if valid @return [Boolean] true if type is one of {TYPES}, else false

# File lib/ssc.bot/chat_log/message.rb, line 67
def self.valid_type?(type)
  return TYPES.include?(type)
end

Public Instance Methods

type?(type) click to toggle source

A convenience method for comparing anything that responds to +:to_sym():+, like String.

@param type [String,Symbol] the type to convert & compare against @return [Boolean] true if this message is of type type, else false

# File lib/ssc.bot/chat_log/message.rb, line 91
def type?(type)
  return @type == type.to_sym
end