Method: Fix::Protocol::Field#to_type

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

#to_type(str) ⇒ Object

Maps a string to an object or a mapped symbol

Parameters:

  • str (String)

    The string to cast or map

Returns:

  • (Object)

     An object of the defined type or a mapped symbol



127
128
129
130
131
132
133
134
135
# File 'lib/fix/protocol/field.rb', line 127

def to_type(str)
  if str && type && !mapping
    send("parse_#{type}", str)
  elsif str && mapping && mapping.values.map(&:to_s).include?(str)
    mapping.find { |k,v| v.to_s == str.to_s }[0]
  else
    str
  end
end