Module: EISCP::Parser::ISCPParser
- Defined in:
- lib/eiscp/parser/iscp_parser.rb
Overview
This module parses an ISCP string and returns a Message object
Constant Summary collapse
- REGEX =
Regexp for parsing ISCP messages
/(?<start>!)?(?<unit_type>(\d|x))?(?<command>[A-Z]{3})\s?(?<value>.*?)(?<terminator>[[:cntrl:]]*$)/
Class Method Summary collapse
Class Method Details
.parse(string) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/eiscp/parser/iscp_parser.rb', line 8 def self.parse(string) match = string.match(REGEX) # Convert MatchData to Hash hash = Hash[match.names.zip(match.captures)] # Remove nil and blank values hash.delete_if { |_, v| v.nil? || v == '' } # Convert keys to symbols hash = hash.inject({}) do |memo, (k, v)| memo[k.to_sym] = v memo end Message.new(**hash) end |