class Fix::Protocol::RepeatingMessagePart
Represents a portion of a FIX message consisting of a similar repeating structure preceded by a counter element
Attributes
counter_tag[RW]
element_klass[RW]
Public Class Methods
new(opts = {})
click to toggle source
Calls superclass method
Fix::Protocol::MessagePart::new
# File lib/fix/protocol/repeating_message_part.rb, line 20 def initialize(opts = {}) @counter_tag = opts[:counter_tag] @element_klass = opts[:klass] super end
Public Instance Methods
build() { |last| ... }
click to toggle source
Appends a new blank node as the last element of the collection
# File lib/fix/protocol/repeating_message_part.rb, line 29 def build nodes << element_klass.new if block_given? yield(nodes.last) end nodes.last end
can_parse?(str)
click to toggle source
Checks whether the start of the given string can be parsed as this particular field
@param str [String] The string for which we want to parse the beginning @return [Boolean] Whether the beginning of the string can be parsed for this field
# File lib/fix/protocol/repeating_message_part.rb, line 54 def can_parse?(str) str =~ /^#{counter_tag}\=[^\x01]+\x01/ end
dump()
click to toggle source
Dumps the message fragment as the set of dumped elements preceded by the relevant counter tag
@return [String] The part of the initial string that didn’t get consumed during the parsing
# File lib/fix/protocol/repeating_message_part.rb, line 44 def dump "#{counter_tag}=#{length}\x01#{super}" end
parse(str)
click to toggle source
Parses an arbitrary number of nodes according to the found counter tag
Calls superclass method
Fix::Protocol::MessagePart#parse
# File lib/fix/protocol/repeating_message_part.rb, line 61 def parse(str) if str.match(/^#{counter_tag}\=([^\x01]+)\x01/) len = $1.to_i @nodes = [] len.times { @nodes << element_klass.new } super(str.gsub(/^#{counter_tag}\=[^\x01]+\x01/, '')) end end