Class: MaxCube::Messages::TCP::Parser
- Inherits:
-
Object
- Object
- MaxCube::Messages::TCP::Parser
- Defined in:
- lib/maxcube/messages/tcp/parser.rb,
lib/maxcube/messages/tcp/type/a.rb,
lib/maxcube/messages/tcp/type/c.rb,
lib/maxcube/messages/tcp/type/f.rb,
lib/maxcube/messages/tcp/type/h.rb,
lib/maxcube/messages/tcp/type/l.rb,
lib/maxcube/messages/tcp/type/m.rb,
lib/maxcube/messages/tcp/type/n.rb,
lib/maxcube/messages/tcp/type/s.rb
Overview
Defined Under Namespace
Modules: MessageA, MessageC, MessageF, MessageH, MessageL, MessageM, MessageN, MessageS
Constant Summary collapse
- MSG_TYPES =
Known message types in the direction Cube -> client.
%w[H F L C M N A E D b g j p o v w S].freeze
Constants included from Handler
Constants included from MaxCube::Messages
DAYS_OF_WEEK, DEVICE_MODE, DEVICE_TYPE
Instance Method Summary collapse
-
#parse_tcp_data(raw_data) ⇒ Array<Hash>
Processes set of messages - raw data separated by \r\n.
-
#parse_tcp_msg(msg) ⇒ Hash
Parses single message already without \r\n.
Methods included from Parser
Methods included from Handler
#check_data_type, #check_hash, #check_hash_keys, #check_hash_msg_type, #check_hash_values, #check_msg, #check_msg_msg_type, #check_msg_type, #msg_type_hash_keys, #msg_type_hash_opt_keys, #valid_data_type, #valid_hash, #valid_hash_keys, #valid_hash_msg_type, #valid_hash_values, #valid_msg, #valid_msg_msg_type, #valid_msg_type
Methods included from Handler
#check_tcp_data, #check_tcp_hash, #check_tcp_msg, #check_tcp_msg_format, #check_tcp_msg_length, #valid_tcp_data, #valid_tcp_hash, #valid_tcp_msg, #valid_tcp_msg_format, #valid_tcp_msg_length
Instance Method Details
#parse_tcp_data(raw_data) ⇒ Array<Hash>
Processes set of messages - raw data separated by \r\n. Calls Handler#check_tcp_data and maps #parse_tcp_msg on each message.
26 27 28 29 |
# File 'lib/maxcube/messages/tcp/parser.rb', line 26 def parse_tcp_data(raw_data) check_tcp_data(raw_data) raw_data.split("\r\n").map(&method(:parse_tcp_msg)) end |
#parse_tcp_msg(msg) ⇒ Hash
Parses single message already without \r\n. Subsequently calls Handler#check_tcp_msg, Parser#parse_msg_body and Handler#check_tcp_hash.
37 38 39 40 41 42 43 |
# File 'lib/maxcube/messages/tcp/parser.rb', line 37 def parse_tcp_msg(msg) check_tcp_msg(msg) body = msg.split(':')[1] || '' hash = { type: @msg_type } return hash unless parse_msg_body(body, hash, 'tcp') check_tcp_hash(hash) end |