module Fix::Protocol::MessageClassMapping

Maps the FIX message type codes to message classes

Constants

MAPPING

The actual code <-> class mapping

Public Class Methods

camelcase(s) click to toggle source

Formats a symbol as a proper class name

@param s [Symbol] A name to camelcase @return [Symbol] A camelcased class name

# 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) click to toggle source

Returns the message class associated to a message code

@param msg_type [Integer] The FIX message type code @return [Class] The FIX message class

# 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) click to toggle source

Returns the message code associated to a message class

@param klass [Class] The FIX message class @return [Integer] The FIX message type code

# 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