Module: Fix::GrammarExtensions::Message

Defined in:
lib/fix/protocol/grammar_extensions/message.rb

Overview

Extends the message component to return the header, body, message type, and checksum from an AST

Instance Method Summary collapse

Instance Method Details

#bodyArray

Returns the FIX message body as a fields array


41
42
43
44
45
# File 'lib/fix/protocol/grammar_extensions/message.rb', line 41

def body
  @fields ||= elements[1].elements.map do |e|
    [ e.elements[0].text_value.to_i, e.elements[2].text_value ]
  end
end

#headerArray

Returns the FIX message header as a fields array


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fix/protocol/grammar_extensions/message.rb', line 19

def header
  unless @header
    hdr = elements[0].elements
    last_fields = hdr.pop

    @header = hdr.map do |e|
      [ e.elements[0].text_value.to_i, e.elements[2].text_value ]
    end

    last_fields.elements.inject(@header) do |h, e|
      h << [ e.elements[0].text_value.to_i, e.elements[2].text_value ]
    end
  end

  @header
end

#msg_typeString

Returns the FIX message type code


52
53
54
# File 'lib/fix/protocol/grammar_extensions/message.rb', line 52

def msg_type
  header.find { |f| f[0] == 35 }[1]
end