Class: LIRC::Messages::ResponseParser
- Inherits:
-
Object
- Object
- LIRC::Messages::ResponseParser
- Defined in:
- lib/lirc/messages/response_parser.rb
Constant Summary collapse
- STATES =
%i[waiting_begin waiting_command waiting_success waiting_data waiting_data_length reading_data valid].freeze
- PARSER_METHOD_FOR =
{ waiting_begin: :parse_begin, waiting_command: :parse_command, waiting_success: :parse_success, waiting_data: :parse_data, waiting_data_length: :parse_data_length, reading_data: :read_data, waiting_end: :parse_end, valid: :raise_already_valid, }.freeze
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(state = :waiting_begin) ⇒ ResponseParser
constructor
A new instance of ResponseParser.
- #parse_line(line) ⇒ Object
-
#valid? ⇒ Boolean
returns true when #message is ready.
Constructor Details
#initialize(state = :waiting_begin) ⇒ ResponseParser
Returns a new instance of ResponseParser.
28 29 30 31 |
# File 'lib/lirc/messages/response_parser.rb', line 28 def initialize(state = :waiting_begin) @state = state @message = Response.new end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
26 27 28 |
# File 'lib/lirc/messages/response_parser.rb', line 26 def @message end |
Instance Method Details
#parse_line(line) ⇒ Object
38 39 40 41 42 |
# File 'lib/lirc/messages/response_parser.rb', line 38 def parse_line(line) line = line.chomp __send__(PARSER_METHOD_FOR.fetch(@state), line) end |
#valid? ⇒ Boolean
returns true when #message is ready
34 35 36 |
# File 'lib/lirc/messages/response_parser.rb', line 34 def valid? @state.equal?(:valid) end |