class CultomePlayer::Objects::Command

Attributes

action[R]
parameters[R]

Public Class Methods

new(action, parameters) click to toggle source
# 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

Public Instance Methods

history?() click to toggle source
# File lib/cultome_player/objects/command.rb, line 13
def history?
  !@no_history
end
params(type=nil) click to toggle source

Returns the parameters, optionally filtered by type

@param type [Symbol] Parameter type to filter the results @return [List<Parameter>] The parameters associated with the command, optionally filtered.

# 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() click to toggle source

Returns a map that contains parameter type as key and a list of the parameters of that type as value.

@return [Hash<Symbol, List<Parameter>>] Parameters grouped by type.

# 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) click to toggle source

Returns a list with only the parameters values of certain type.

@param type [Symbol] The type of parameters. @return [List<Object>] The values of the parameters.

# File lib/cultome_player/objects/command.rb, line 37
def params_values(type)
  params(type).map{|p| p.value }
end
to_s() click to toggle source
# File lib/cultome_player/objects/command.rb, line 41
def to_s
  "#{action} #{@parameters.join(" ")}"
end