11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/hypertube-ruby-sdk/sdk/tools/get_instance_field_helper.rb', line 11
def get_field_value(command, field_name)
return nil if command.nil? || command.payload.nil? || command.payload.empty?
if command.command_type == Hypertube::Utils::CommandType::SET_INSTANCE_FIELD && command.payload.length >= 3
name = get_payload_value(command.payload[1])
return get_payload_value(command.payload[2]) if name.is_a?(String) && name == field_name
end
if command.command_type == Hypertube::Utils::CommandType::ARRAY
command.payload.each do |item|
if item.is_a?(Hypertube::Utils::Command)
result = get_field_value(item, field_name)
return result unless result.nil?
end
end
return nil
end
first_payload = command.payload[0]
return get_field_value(first_payload, field_name) if first_payload.is_a?(Hypertube::Utils::Command)
nil
end
|