Class: Protor::UDPFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/protor/udp_formatter.rb

Constant Summary collapse

LF =
"\n".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_packet_size) ⇒ UDPFormatter

Returns a new instance of UDPFormatter.



7
8
9
# File 'lib/protor/udp_formatter.rb', line 7

def initialize(max_packet_size)
  @max_packet_size = max_packet_size
end

Instance Attribute Details

#max_packet_sizeObject (readonly)

Returns the value of attribute max_packet_size.



3
4
5
# File 'lib/protor/udp_formatter.rb', line 3

def max_packet_size
  @max_packet_size
end

Instance Method Details

#format(registry) {|str| ... } ⇒ Object

Yields:

  • (str)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/protor/udp_formatter.rb', line 11

def format(registry)
  return unless block_given?

  str = ""
  size = 0
  registry.each do |entry|
    line = stringify(entry)

    if size + line.size > max_packet_size
      yield(str)
      str = line
      size = line.size
    else
      str << line
      size += line.size
    end
  end
  yield(str)
end