Class: Fix::Protocol::RepeatingMessagePart
- Inherits:
-
MessagePart
- Object
- MessagePart
- Fix::Protocol::RepeatingMessagePart
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/fix/protocol/repeating_message_part.rb
Overview
Represents a portion of a FIX message consisting of a similar repeating structure preceded by a counter element
Instance Attribute Summary collapse
-
#counter_tag ⇒ Object
Returns the value of attribute counter_tag.
-
#element_klass ⇒ Object
Returns the value of attribute element_klass.
Attributes inherited from MessagePart
#delegations, #name, #parse_failure
Instance Method Summary collapse
-
#build ⇒ Object
Appends a new blank node as the last element of the collection.
-
#can_parse?(str) ⇒ Boolean
Checks whether the start of the given string can be parsed as this particular field.
-
#dump ⇒ String
Dumps the message fragment as the set of dumped elements preceded by the relevant counter tag.
-
#initialize(opts = {}) ⇒ RepeatingMessagePart
constructor
A new instance of RepeatingMessagePart.
-
#parse(str) ⇒ Object
Parses an arbitrary number of nodes according to the found counter tag.
Methods inherited from MessagePart
collection, #errors, field, inherited, #initialize_node, #node_for_name, #nodes, parent_delegate, parse, part, structure, unordered
Constructor Details
#initialize(opts = {}) ⇒ RepeatingMessagePart
Returns a new instance of RepeatingMessagePart.
20 21 22 23 24 |
# File 'lib/fix/protocol/repeating_message_part.rb', line 20 def initialize(opts = {}) @counter_tag = opts[:counter_tag] @element_klass = opts[:klass] super end |
Instance Attribute Details
#counter_tag ⇒ Object
Returns the value of attribute counter_tag.
18 19 20 |
# File 'lib/fix/protocol/repeating_message_part.rb', line 18 def counter_tag @counter_tag end |
#element_klass ⇒ Object
Returns the value of attribute element_klass.
18 19 20 |
# File 'lib/fix/protocol/repeating_message_part.rb', line 18 def element_klass @element_klass end |
Instance Method Details
#build ⇒ Object
Appends a new blank node as the last element of the collection
29 30 31 32 33 34 35 36 37 |
# 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) ⇒ Boolean
Checks whether the start of the given string can be parsed as this particular field
54 55 56 |
# File 'lib/fix/protocol/repeating_message_part.rb', line 54 def can_parse?(str) str =~ /^#{counter_tag}\=[^\x01]+\x01/ end |
#dump ⇒ String
Dumps the message fragment as the set of dumped elements preceded by the relevant counter tag
44 45 46 |
# File 'lib/fix/protocol/repeating_message_part.rb', line 44 def dump "#{counter_tag}=#{length}\x01#{super}" end |
#parse(str) ⇒ Object
Parses an arbitrary number of nodes according to the found counter tag
61 62 63 64 65 66 67 68 |
# 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 |