module Fix::Protocol::TypeConversions

Defines helper methods to convert to and from FIX data types

Public Instance Methods

dump_integer(i) click to toggle source

Dumps an integer to a string

@param i [Fixnum] An integer @return [String] It’s string representation

# File lib/fix/protocol/type_conversions.rb, line 48
def dump_integer(i)
  i.to_s
end
dump_timestamp(dt) click to toggle source

Outputs a DateTime object as a FIX-formatted timestamp

@param dt [DateTime] An UTC date and time @return [String] A FIX-formatted timestamp

# File lib/fix/protocol/type_conversions.rb, line 28
def dump_timestamp(dt)
  dt.utc.strftime('%Y%m%d-%H:%M:%S')
end
dump_yn_bool(b) click to toggle source

Dumps a boolean to a Y/N FIX string

@param b [Boolean] A boolean @return [String] ‘Y’ if the parameter is true, ‘N’ otherwise

# File lib/fix/protocol/type_conversions.rb, line 58
def dump_yn_bool(b)
  b ? 'Y' : 'N'
end
parse_integer(str) click to toggle source

Parses an integer

@param str [String] An integer as a string @return [Fixnum] The parsed integer

# File lib/fix/protocol/type_conversions.rb, line 38
def parse_integer(str)
  str && str.to_i
end
parse_timestamp(str) click to toggle source

Parses a FIX-formatted timestamp into a Time instance, milliseconds are discarded

@param str [String] A FIX-formatted timestamp @return [Time] An UTC date and time

# File lib/fix/protocol/type_conversions.rb, line 15
def parse_timestamp(str)
  if m = str.match(/\A([0-9]{4})([0-9]{2})([0-9]{2})-([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]{3})?\Z/)
    elts = m.to_a.map(&:to_i)
    Time.new(elts[1], elts[2], elts[3], elts[4], elts[5], elts[6], 0)
  end
end
parse_yn_bool(str) click to toggle source

Parses a string into a boolean value

@param str [String] The string to parse @return [Boolean] true if the string is ‘Y’, false otherwise

# File lib/fix/protocol/type_conversions.rb, line 68
def parse_yn_bool(str)
  !!(str == 'Y')
end