Module: MaxCube::Messages::TCP::Handler
Overview
Extends Handler of routines connected to TCP Cube messages.
Constant Summary
Constants included from Handler
Constants included from MaxCube::Messages
DAYS_OF_WEEK, DEVICE_MODE, DEVICE_TYPE
Instance Method Summary collapse
-
#check_tcp_data(raw_data) ⇒ String
As #valid_tcp_data, but raises exception if raw data is not valid.
-
#check_tcp_hash(hash) ⇒ Hash
As #valid_tcp_hash, but raises exception if hash is not valid.
-
#check_tcp_msg(msg) ⇒ String
As #valid_tcp_msg, but raises exception if message is not valid.
-
#check_tcp_msg_format(msg) ⇒ String
As #valid_tcp_msg_format, but raises exception if message format is not valid.
-
#check_tcp_msg_length(msg) ⇒ Integer
As #valid_tcp_msg_length, but raises exception if message length is not valid.
-
#valid_tcp_data(raw_data) ⇒ Boolean
Validates whether input raw data containing multiple separated TCP Cube messages is valid.
-
#valid_tcp_hash(hash) ⇒ Boolean
Validates whether given hash with message contents is valid for TCP Cube messaging purposes.
-
#valid_tcp_msg(msg) ⇒ Boolean
Validates whether given message is a valid TCP Cube message.
-
#valid_tcp_msg_format(msg) ⇒ Boolean
Validates whether message satisfies TCP Cube format (see MaxCube::Messages::TCP).
-
#valid_tcp_msg_length(msg) ⇒ Boolean
Validates whether message satisfies MSG_MAX_LEN.
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
Instance Method Details
#check_tcp_data(raw_data) ⇒ String
As #valid_tcp_data, but raises exception if raw data is not valid.
102 103 104 105 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 102 def check_tcp_data(raw_data) raise InvalidMessageFormat unless valid_tcp_data(raw_data) raw_data end |
#check_tcp_hash(hash) ⇒ Hash
As #valid_tcp_hash, but raises exception if hash is not valid. It only calls Handler#check_hash.
81 82 83 84 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 81 def check_tcp_hash(hash) check_hash(hash) hash end |
#check_tcp_msg(msg) ⇒ String
As #valid_tcp_msg, but raises exception if message is not valid. It calls #check_tcp_msg_length, #check_tcp_msg_format and Handler#check_msg.
61 62 63 64 65 66 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 61 def check_tcp_msg(msg) check_tcp_msg_length(msg) check_tcp_msg_format(msg) check_msg(msg) msg end |
#check_tcp_msg_format(msg) ⇒ String
As #valid_tcp_msg_format, but raises exception if message format is not valid.
40 41 42 43 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 40 def check_tcp_msg_format(msg) raise InvalidMessageFormat unless valid_tcp_msg_format(msg) msg end |
#check_tcp_msg_length(msg) ⇒ Integer
As #valid_tcp_msg_length, but raises exception if message length is not valid.
23 24 25 26 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 23 def check_tcp_msg_length(msg) raise InvalidMessageLength unless valid_tcp_msg_length(msg) msg.length end |
#valid_tcp_data(raw_data) ⇒ Boolean
Validates whether input raw data containing multiple separated TCP Cube messages is valid. It only checks \r\n stuff. It does not validate data type (Handler#valid_data_type), yet? It does not validate particular messages.
93 94 95 96 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 93 def valid_tcp_data(raw_data) return true if raw_data.empty? raw_data[0..1] != "\r\n" && raw_data.chars.last(2).join == "\r\n" end |
#valid_tcp_hash(hash) ⇒ Boolean
Validates whether given hash with message contents is valid for TCP Cube messaging purposes. It only calls Handler#valid_hash.
73 74 75 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 73 def valid_tcp_hash(hash) valid_hash(hash) end |
#valid_tcp_msg(msg) ⇒ Boolean
Validates whether given message is a valid TCP Cube message. It calls #valid_tcp_msg_length, #valid_tcp_msg_format and Handler#valid_msg.
50 51 52 53 54 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 50 def valid_tcp_msg(msg) valid_tcp_msg_length(msg) && valid_tcp_msg_format(msg) && valid_msg(msg) end |
#valid_tcp_msg_format(msg) ⇒ Boolean
Validates whether message satisfies TCP Cube format (see MaxCube::Messages::TCP).
31 32 33 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 31 def valid_tcp_msg_format(msg) msg =~ /\A[[:alpha:]]:[[:print:]]*\z/ end |
#valid_tcp_msg_length(msg) ⇒ Boolean
Validates whether message satisfies MSG_MAX_LEN.
14 15 16 |
# File 'lib/maxcube/messages/tcp/handler.rb', line 14 def valid_tcp_msg_length(msg) msg.length.between?(2, MSG_MAX_LEN) end |