Module: Fix::Protocol::TypeConversions
- Included in:
- Field
- Defined in:
- lib/fix/protocol/type_conversions.rb
Overview
Defines helper methods to convert to and from FIX data types
Instance Method Summary collapse
-
#dump_integer(i) ⇒ String
Dumps an integer to a string.
-
#dump_timestamp(dt) ⇒ String
Outputs a DateTime object as a FIX-formatted timestamp.
-
#dump_yn_bool(b) ⇒ String
Dumps a boolean to a Y/N FIX string.
-
#parse_integer(str) ⇒ Fixnum
Parses an integer.
-
#parse_timestamp(str) ⇒ Time
Parses a FIX-formatted timestamp into a Time instance, milliseconds are discarded.
-
#parse_yn_bool(str) ⇒ Boolean
Parses a string into a boolean value.
Instance Method Details
#dump_integer(i) ⇒ String
Dumps an integer to a string
48 49 50 |
# File 'lib/fix/protocol/type_conversions.rb', line 48 def dump_integer(i) i.to_s end |
#dump_timestamp(dt) ⇒ String
Outputs a DateTime object as a FIX-formatted timestamp
28 29 30 |
# File 'lib/fix/protocol/type_conversions.rb', line 28 def (dt) dt.utc.strftime('%Y%m%d-%H:%M:%S') end |
#dump_yn_bool(b) ⇒ String
Dumps a boolean to a Y/N FIX string
58 59 60 |
# File 'lib/fix/protocol/type_conversions.rb', line 58 def dump_yn_bool(b) b ? 'Y' : 'N' end |
#parse_integer(str) ⇒ Fixnum
Parses an integer
38 39 40 |
# File 'lib/fix/protocol/type_conversions.rb', line 38 def parse_integer(str) str && str.to_i end |
#parse_timestamp(str) ⇒ Time
Parses a FIX-formatted timestamp into a Time instance, milliseconds are discarded
15 16 17 18 19 20 |
# File 'lib/fix/protocol/type_conversions.rb', line 15 def (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) ⇒ Boolean
Parses a string into a boolean value
68 69 70 |
# File 'lib/fix/protocol/type_conversions.rb', line 68 def parse_yn_bool(str) !!(str == 'Y') end |