class FixProtocolTools::Specification::Reader

Constants

SPECIFICATION_PATH

Attributes

enums[R]
fields[R]
max_field_length[R]
message_types[R]

Public Class Methods

new() click to toggle source
# File lib/fix_protocol_tools/specification/reader.rb, line 26
def initialize
  @message_types = {}
  @fields = {}
  @enums = Hash.new { |h, k| h[k] = {} }

  @max_field_length = 0
end
read_defaults(fix_version) click to toggle source
# File lib/fix_protocol_tools/specification/reader.rb, line 11
def self.read_defaults(fix_version)
  path = File.join(SPECIFICATION_PATH, fix_version.delete('.') + '.xml')
  read_file(path)
end
read_file(path) click to toggle source
# File lib/fix_protocol_tools/specification/reader.rb, line 16
def self.read_file(path)
  reader = new

  File.open(path, 'r') do |file|
    REXML::Document.parse_stream(file, reader)
  end

  reader
end

Public Instance Methods

tag_start(tag_name, attrs) click to toggle source
# File lib/fix_protocol_tools/specification/reader.rb, line 34
def tag_start(tag_name, attrs)
  if message?(attrs, tag_name)
    @message_types[attrs['msgtype']] = attrs['name']
  end

  if field_definition?(attrs, tag_name)
    @current_field = attrs['number']
    @fields[attrs['number']] = attrs['name']
  end

  if enum_value?(attrs, tag_name)
    @enums[@current_field][attrs['enum']] = attrs['description']
  end

  if attrs.has_key? 'name'
    @max_field_length = [@max_field_length, attrs['name'].length].max
  end
end

Private Instance Methods

enum_value?(attrs, tag_name) click to toggle source
# File lib/fix_protocol_tools/specification/reader.rb, line 59
def enum_value?(attrs, tag_name)
  tag_name == 'value' && attrs.has_key?('enum')
end
field_definition?(attrs, tag_name) click to toggle source
# File lib/fix_protocol_tools/specification/reader.rb, line 55
def field_definition?(attrs, tag_name)
  tag_name == 'field' && attrs.has_key?('number') && attrs.has_key?('name')
end
message?(attrs, tag_name) click to toggle source
# File lib/fix_protocol_tools/specification/reader.rb, line 63
def message?(attrs, tag_name)
  tag_name == 'message' && attrs.has_key?('name') != nil && attrs['msgtype'] != nil && attrs['msgcat'] != nil
end