Class: Protor::Payload
- Inherits:
-
Object
- Object
- Protor::Payload
- Defined in:
- lib/protor/payload.rb
Constant Summary collapse
- Lf =
"\n".freeze
Instance Method Summary collapse
- #add(data) ⇒ Object
-
#initialize(max_packet_size) ⇒ Payload
constructor
A new instance of Payload.
- #to_s ⇒ Object
Constructor Details
#initialize(max_packet_size) ⇒ Payload
Returns a new instance of Payload.
7 8 9 10 11 |
# File 'lib/protor/payload.rb', line 7 def initialize(max_packet_size) @max_packet_size = max_packet_size @lines = [] @total_size = 0 end |
Instance Method Details
#add(data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/protor/payload.rb', line 13 def add(data) data = data.dup data[:first] = true if lines.empty? if data[:labels] data[:labels].delete_if{ |k, v| v.to_s.empty? } else data[:labels] = {} end return false if packet_overflow?(data) self.common_labels = data[:labels] @total_size += data_size(data) @lines << data end |
#to_s ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/protor/payload.rb', line 30 def to_s str = first_line lines.each do |data| line = template(data) str << "#{line}#{Lf}" end return str end |