Class: Hlockey::Message
- Inherits:
-
Object
- Object
- Hlockey::Message
- Defined in:
- lib/hlockey/message.rb
Overview
Can be sent by a Game (in Game#stream) or a commonly used text
Class Attribute Summary collapse
-
.colorize ⇒ Object
writeonly
Variable controlling how coloring players/teams is done Set this to a Proc that takes params ‘color` and `string`, and returns the colorized string.
Instance Attribute Summary collapse
-
#event ⇒ Symbol
readonly
An action or event the message represents.
Class Method Summary collapse
-
.color(obj, do_color: true) ⇒ Object
Colors Team/associated classes in their team color To control how this colors things, see #colorize=.
Instance Method Summary collapse
-
#initialize(event, **data) ⇒ Message
constructor
A new instance of Message.
- #to_s(do_color: true) ⇒ Object
Constructor Details
#initialize(event, **data) ⇒ Message
Returns a new instance of Message.
15 16 17 18 |
# File 'lib/hlockey/message.rb', line 15 def initialize(event, **data) @event = event @data = data end |
Class Attribute Details
.colorize=(value) ⇒ Object (writeonly)
Variable controlling how coloring players/teams is done Set this to a Proc that takes params ‘color` and `string`, and returns the colorized string. `color` will be in hex format, for example “#ffffff” The default is to not color things at all
34 35 36 |
# File 'lib/hlockey/message.rb', line 34 def colorize=(value) @colorize = value end |
Instance Attribute Details
#event ⇒ Symbol (readonly)
Returns an action or event the message represents.
11 12 13 |
# File 'lib/hlockey/message.rb', line 11 def event @event end |
Class Method Details
.color(obj, do_color: true) ⇒ Object
Colors Team/associated classes in their team color To control how this colors things, see #colorize=
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hlockey/message.rb', line 40 def color(obj, do_color: true) return obj.to_s unless do_color case obj when Team @colorize.call(obj.color, obj.to_s) when Team::Player, Team::Stadium @colorize.call(obj.team.color, obj.to_s) else obj.to_s end end |