Class: Grid::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/grid/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params) ⇒ Command

Returns a new instance of Command.



7
8
9
# File 'lib/grid/command.rb', line 7

def initialize(name, params)
  @name, @params = name, params
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/grid/command.rb', line 5

def name
  @name
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/grid/command.rb', line 5

def params
  @params
end

Class Method Details

.parse(body) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/grid/command.rb', line 11

def self.parse(body)
  return if body == ''

  data = JSON.parse(body)

  cmd = Command.new(
    data['name'].to_sym,
    data['params']
  )

  cmd
end

Instance Method Details

#encodeObject



24
25
26
27
28
29
# File 'lib/grid/command.rb', line 24

def encode
  JSON.unparse(
    :name => @name,
    :params => @params
  )
end