Class: CultomePlayer::Objects::Command
- Inherits:
-
Object
- Object
- CultomePlayer::Objects::Command
- Defined in:
- lib/cultome_player/objects/command.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
- #history? ⇒ Boolean
-
#initialize(action, parameters) ⇒ Command
constructor
A new instance of Command.
-
#params(type = nil) ⇒ List<Parameter>
Returns the parameters, optionally filtered by type.
-
#params_groups ⇒ Hash<Symbol, List<Parameter>>
Returns a map that contains parameter type as key and a list of the parameters of that type as value.
-
#params_values(type) ⇒ List<Object>
Returns a list with only the parameters values of certain type.
- #to_s ⇒ Object
Constructor Details
#initialize(action, parameters) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 |
# File 'lib/cultome_player/objects/command.rb', line 7 def initialize(action, parameters) @action = action[:value] @parameters = parameters.collect{|p| Parameter.new(p) } @no_history = params(:literal).any?{|p| p.value == 'no_history'} end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
4 5 6 |
# File 'lib/cultome_player/objects/command.rb', line 4 def action @action end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
5 6 7 |
# File 'lib/cultome_player/objects/command.rb', line 5 def parameters @parameters end |
Instance Method Details
#history? ⇒ Boolean
13 14 15 |
# File 'lib/cultome_player/objects/command.rb', line 13 def history? !@no_history end |
#params(type = nil) ⇒ List<Parameter>
Returns the parameters, optionally filtered by type
21 22 23 24 |
# File 'lib/cultome_player/objects/command.rb', line 21 def params(type=nil) return @parameters if type.nil? @parameters.select{|p| p.type == type} end |
#params_groups ⇒ Hash<Symbol, List<Parameter>>
Returns a map that contains parameter type as key and a list of the parameters of that type as value.
29 30 31 |
# File 'lib/cultome_player/objects/command.rb', line 29 def params_groups @parameters.collect{|p| p.type }.each_with_object({}){|type,acc| acc[type] = params(type) } end |
#params_values(type) ⇒ List<Object>
Returns a list with only the parameters values of certain type.
37 38 39 |
# File 'lib/cultome_player/objects/command.rb', line 37 def params_values(type) params(type).map{|p| p.value } end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/cultome_player/objects/command.rb', line 41 def to_s "#{action} #{@parameters.join(" ")}" end |