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
Public Class Methods
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
@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
@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
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