class Protor::UDPFormatter
Constants
- LF
Attributes
max_packet_size[R]
Public Class Methods
new(max_packet_size)
click to toggle source
# File lib/protor/udp_formatter.rb, line 7 def initialize(max_packet_size) @max_packet_size = max_packet_size end
Public Instance Methods
format(registry) { |str| ... }
click to toggle source
# 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
Private Instance Methods
additional_string(additional)
click to toggle source
# File lib/protor/udp_formatter.rb, line 45 def additional_string(additional) additional.join(';') end
labels_string(labels)
click to toggle source
# File lib/protor/udp_formatter.rb, line 41 def labels_string(labels) labels.map{ |k, v| "#{k}=#{v}" }.join(';') end
stringify(entry)
click to toggle source
# File lib/protor/udp_formatter.rb, line 33 def stringify(entry) "#{ entry.name }|#{ entry.type }|".tap do |str| str << "#{ additional_string(entry.additional) }|" unless entry.additional.empty? str << "#{ labels_string(entry.labels) }|" unless entry.labels.empty? str << "#{ entry.value }#{LF}" end end