Module: Fix::Protocol::MessageClassMapping

Defined in:
lib/fix/protocol/message_class_mapping.rb

Overview

Maps the FIX message type codes to message classes

Constant Summary collapse

MAPPING =

The actual code <-> class mapping

{
  '0' => :heartbeat,
  'A' => :logon,
  '1' => :test_request,
  '2' => :resend_request,
  '3' => :reject,
  '5' => :logout,
  'V' => :market_data_request,
  'W' => :market_data_snapshot,
  'X' => :market_data_incremental_refresh
}

Class Method Summary collapse

Class Method Details

.camelcase(s) ⇒ Symbol

Formats a symbol as a proper class name

Parameters:

  • s (Symbol)

    A name to camelcase

Returns:

  • (Symbol)

    A camelcased class name



51
52
53
# File 'lib/fix/protocol/message_class_mapping.rb', line 51

def self.camelcase(s)
  s.to_s.split(' ').map { |str| str.split('_') }.flatten.map(&:capitalize).join.to_sym
end

.get(msg_type) ⇒ Class

Returns the message class associated to a message code

Parameters:

  • msg_type (Integer)

    The FIX message type code

Returns:

  • (Class)

    The FIX message class



30
31
32
# File 'lib/fix/protocol/message_class_mapping.rb', line 30

def self.get(msg_type)
  Messages.const_get(camelcase(MAPPING[msg_type])) if MAPPING.has_key?(msg_type)
end

.reverse_get(klass) ⇒ Integer

Returns the message code associated to a message class

Parameters:

  • klass (Class)

    The FIX message class

Returns:

  • (Integer)

    The FIX message type code



40
41
42
43
# File 'lib/fix/protocol/message_class_mapping.rb', line 40

def self.reverse_get(klass)
  key = klass.name.split('::').last.gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase.to_sym
  MAPPING.find { |p| p[1] == key }[0]
end