module EISCP::Parser::ISCPParser

This module parses an ISCP string and returns a Message object

Constants

REGEX

Regexp for parsing ISCP messages

Public Class Methods

parse(string) click to toggle source
# File lib/eiscp/parser/iscp_parser.rb, line 10
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.transform_keys(&:to_sym)

  Message.new(**hash)
end