Class: RSMP::CommandList
- Inherits:
-
Object
- Object
- RSMP::CommandList
- Includes:
- Enumerable
- Defined in:
- lib/rsmp/command_list.rb
Overview
Represents an RSMP command list and converts between the two common formats:
Compact form (used in validators and helpers):
RSMP::CommandList.new(:M0001, :setValue, securityCode: '1111', status: 'NormalControl')
Raw wire Array (used in RSMP messages):
[
{ 'cCI' => 'M0001', 'cO' => 'setValue', 'n' => 'securityCode', 'v' => '1111' },
{ 'cCI' => 'M0001', 'cO' => 'setValue', 'n' => 'status', 'v' => 'NormalControl' }
]
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(command_code_id, command_name, values) ⇒ CommandList
constructor
A new instance of CommandList.
- #to_a ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(command_code_id, command_name, values) ⇒ CommandList
Returns a new instance of CommandList.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rsmp/command_list.rb', line 15 def initialize(command_code_id, command_name, values) @list = values.compact.map do |n, v| { 'cCI' => command_code_id.to_s, 'cO' => command_name.to_s, 'n' => n.to_s, 'v' => v.to_s } end end |
Instance Method Details
#each ⇒ Object
26 27 28 |
# File 'lib/rsmp/command_list.rb', line 26 def each(&) @list.each(&) end |
#to_a ⇒ Object
30 31 32 |
# File 'lib/rsmp/command_list.rb', line 30 def to_a @list end |
#to_h ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rsmp/command_list.rb', line 34 def to_h @list.each_with_object({}) do |item, hash| code = item['cCI'] command = item['cO'] ((hash[code] ||= {})[command] ||= {})[item['n']] = item['v'] end end |