Method: CMF::Parser#parse

Defined in:
lib/cmf/parser.rb

#parse(message = nil) ⇒ Hash

Parses a CMF message into an object.

Parameters:

  • message (String) (defaults to: nil)

    The message to parse. If none provided, this parser's existing message (defined from #message= or #message_hex= will be parsed.

Returns:

  • (Hash)

    A hash mapping the messages tags to their values. For each tag, if the tag number is found in the dictionary, its associated tag name will be used as hash key. If a tag is found multiple times in the message, its values will be stored in an array in the parsed object.

[View source]

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cmf/parser.rb', line 71

def parse(message = nil)
  self.message = message if message

  obj = {}
  each do |key, value|
    if obj.has_key?(key)
      obj[key] = Array(obj[key])
      obj[key] << value
    else
      obj[key] = value
    end
  end

  obj
end