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,
  '4' => :sequence_reset,
  '5' => :logout,
  'V' => :market_data_request,
  'W' => :market_data_snapshot,
  'X' => :market_data_incremental_refresh,
  'j' => :business_message_reject
}

Class Method Summary collapse

Class Method Details

.camelcase(s) ⇒ Symbol

Formats a symbol as a proper class name



53
54
55
# File 'lib/fix/protocol/message_class_mapping.rb', line 53

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



32
33
34
# File 'lib/fix/protocol/message_class_mapping.rb', line 32

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



42
43
44
45
# File 'lib/fix/protocol/message_class_mapping.rb', line 42

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