Class: SSCBot::ChatLog::Message
- Inherits:
-
Object
- Object
- SSCBot::ChatLog::Message
- Extended by:
- AttrBool::Ext
- Defined in:
- lib/ssc.bot/chat_log/message.rb
Overview
The base class of all parsed messages from a chat log file.
Direct Known Subclasses
KillMessage, PlayerMessage, QFindMessage, QLogMessage, QNamelenMessage
Constant Summary collapse
- TYPES =
Set.new
Instance Attribute Summary collapse
-
#line ⇒ String
readonly
The raw (unparsed) line from the file.
-
#type ⇒ Symbol
readonly
What type of message this is; one of TYPES.
Class Method Summary collapse
-
.add_type(type) ⇒ Object
Adds
type
to the list of valid TYPES and creates a boolean method for it ending with a ?. -
.valid_type?(type) ⇒ Boolean
true
iftype
is one of TYPES, elsefalse
.
Instance Method Summary collapse
-
#initialize(line, type:) ⇒ Message
constructor
A new instance of Message.
-
#type?(type) ⇒ Boolean
A convenience method for comparing anything that responds to :to_sym():, like
String
.
Constructor Details
#initialize(line, type:) ⇒ Message
Returns a new instance of Message.
76 77 78 79 80 81 82 83 84 |
# 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 |
Instance Attribute Details
#line ⇒ String (readonly)
Returns the raw (unparsed) line from the file.
71 72 73 |
# File 'lib/ssc.bot/chat_log/message.rb', line 71 def line @line end |
#type ⇒ Symbol (readonly)
Returns what type of message this is; one of TYPES.
72 73 74 |
# File 'lib/ssc.bot/chat_log/message.rb', line 72 def type @type end |
Class Method Details
.add_type(type) ⇒ Object
Adds type
to the list of valid TYPES and creates a boolean method for it ending with a ?.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |
Instance Method Details
#type?(type) ⇒ Boolean
A convenience method for comparing anything that responds to :to_sym():, like String
.
91 92 93 |
# File 'lib/ssc.bot/chat_log/message.rb', line 91 def type?(type) return @type == type.to_sym end |