Module: FIXSpec::Helpers
Instance Method Summary collapse
- #extract_message_type(msg) ⇒ Object
- #field_map_to_hash(field_map, data_dictionary = FIXSpec::data_dictionary, msg_type = nil, all_dictionaries = [ data_dictionary ]) ⇒ Object
- #find_field_name(tag, data_dictionaries = []) ⇒ Object
- #find_field_type(tag, data_dictionaries = []) ⇒ Object
- #fixify_string(msg_str) ⇒ Object
- #message_to_hash(msg) ⇒ Object
- #message_to_unordered_json(msg) ⇒ Object
Instance Method Details
#extract_message_type(msg) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/fix_spec/helpers.rb', line 36 def msg if msg.is_set_field( quickfix::field::MsgType::FIELD) msg.get_field(quickfix::field::MsgType::FIELD).get_value else nil end end |
#field_map_to_hash(field_map, data_dictionary = FIXSpec::data_dictionary, msg_type = nil, all_dictionaries = [ data_dictionary ]) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fix_spec/helpers.rb', line 59 def field_map_to_hash field_map, data_dictionary = FIXSpec::data_dictionary, msg_type = nil, all_dictionaries = [ data_dictionary ] hash = {} iter = field_map.iterator while iter.has_next field = iter.next() tag = field.get_tag value = field.get_value if !data_dictionary.nil? if !msg_type.nil? and data_dictionary.is_group(msg_type, tag) group_dd = data_dictionary.get_group(msg_type,tag).get_data_dictionary groups = [] for i in 1..value.to_i groups << field_map_to_hash( field_map.get_group(i,tag), group_dd, msg_type,Array.new(all_dictionaries) << group_dd ) end value = groups elsif data_dictionary.is_field(tag) value = case find_field_type(tag,all_dictionaries) when "INT","DAYOFMONTH" then value.to_i when "PRICE","FLOAT","QTY" then value.to_f when "BOOLEAN" then value == "Y" when "NUMINGROUP" then value = field_map.to_hash(value) else value_name = data_dictionary.get_value_name(tag, value) unless value_name.nil? value_name else value end end end tag = find_field_name(tag,all_dictionaries) end hash[tag] = value end return hash end |
#find_field_name(tag, data_dictionaries = []) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/fix_spec/helpers.rb', line 52 def find_field_name tag, data_dictionaries = [] data_dictionaries.each do |dd| value = dd.get_field_name(tag) return value unless value.nil? or value.eql?("") end end |
#find_field_type(tag, data_dictionaries = []) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/fix_spec/helpers.rb', line 44 def find_field_type tag, data_dictionaries = [] data_dictionaries.each do |dd| enum = dd.get_field_type_enum(tag) value = enum.get_name unless enum.nil? return value unless value.nil? or value.eql?("") end end |
#fixify_string(msg_str) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fix_spec/helpers.rb', line 6 def fixify_string msg_str = msg_str.strip begin_string = .slice!(/^8=.*?[\001]/) raise "Message '#{msg_str}' has no begin string" if begin_string.nil? #nobody's perfect, allow for missing trailing soh +="\001" unless .end_with?("\001") #auto-calc length and checksum, ignore any existing .slice!(/^9=\d+\001/) .gsub!(/10=\d\d\d\001$/,"") length = "9=#{.length}\001" checksum = "10=%03d\001" % (begin_string + length + ).sum(8) return (begin_string + length + + checksum) end |
#message_to_hash(msg) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/fix_spec/helpers.rb', line 28 def msg header = msg.get_header msg_type = header msg_hash = field_map_to_hash header msg_hash.merge! field_map_to_hash msg, FIXSpec::data_dictionary, msg_type msg_hash.merge field_map_to_hash msg.get_trailer end |
#message_to_unordered_json(msg) ⇒ Object
24 25 26 |
# File 'lib/fix_spec/helpers.rb', line 24 def msg MultiJson.encode (msg) end |