Class: Turntabler::Event Private
- Inherits:
-
Object
- Object
- Turntabler::Event
- Defined in:
- lib/turntabler/event.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides access to all of the events that get triggered by incoming messages from the Turntable API
Class Attribute Summary collapse
-
.commands ⇒ Hash<String, String>
readonly
private
Maps Turntable command => event name.
Instance Attribute Summary collapse
-
#args ⇒ Array<Object>
readonly
private
The raw arguments list from the event.
-
#data ⇒ Hash<String, Object>
readonly
private
The raw hash of data parsed from the event.
-
#name ⇒ String
readonly
private
The name of the event that was triggered.
-
#results ⇒ Array<Array<Object>>
readonly
private
The typecasted results args parsed from the event.
Class Method Summary collapse
-
.command?(command) ⇒ Boolean
private
Determines whether the given command is handled.
-
.handle(name, command = name) {|data| ... } ⇒ nil
private
Defines a new event that maps to the given Turntable command.
Instance Method Summary collapse
-
#initialize(client, command, args) ⇒ Event
constructor
private
Creates a new event triggered with the given data.
Constructor Details
#initialize(client, command, args) ⇒ Event
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new event triggered with the given data
300 301 302 303 304 305 306 307 |
# File 'lib/turntabler/event.rb', line 300 def initialize(client, command, args) @client = client @args = args @data = args[0] @name = self.class.commands[command] @results = __send__("typecast_#{command}_event") @results = [[@results].compact] unless @results.is_a?(Array) end |
Class Attribute Details
.commands ⇒ Hash<String, String> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Maps Turntable command => event name
14 15 16 |
# File 'lib/turntabler/event.rb', line 14 def commands @commands end |
Instance Attribute Details
#args ⇒ Array<Object> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The raw arguments list from the event
285 286 287 |
# File 'lib/turntabler/event.rb', line 285 def args @args end |
#data ⇒ Hash<String, Object> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The raw hash of data parsed from the event
289 290 291 |
# File 'lib/turntabler/event.rb', line 289 def data @data end |
#name ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The name of the event that was triggered
281 282 283 |
# File 'lib/turntabler/event.rb', line 281 def name @name end |
#results ⇒ Array<Array<Object>> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The typecasted results args parsed from the event
293 294 295 |
# File 'lib/turntabler/event.rb', line 293 def results @results end |
Class Method Details
.command?(command) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines whether the given command is handled.
37 38 39 |
# File 'lib/turntabler/event.rb', line 37 def command?(command) commands.include?(command) end |
.handle(name, command = name) {|data| ... } ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines a new event that maps to the given Turntable command. The block defines how to typecast the data that is received from Turntable.
25 26 27 28 29 30 31 |
# File 'lib/turntabler/event.rb', line 25 def handle(name, command = name, &block) block ||= lambda { [args] } commands[command] = name define_method("typecast_#{command}_event", &block) protected :"typecast_#{command}_event" end |