Class: StreamWrapper::OrderBlobSplitter

Inherits:
Object
  • Object
show all
Defined in:
lib/logbox/stream_wrapper/order_blob_splitter.rb

Overview

Modfies and injects buy_basket blob information into stream.

  1. Inserts attributes from buy_basket blob into the buy_basket observation.

  2. Adds a buy_item observation for each item in the basket.

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ OrderBlobSplitter

Returns a new instance of OrderBlobSplitter.



9
10
11
12
13
# File 'lib/logbox/stream_wrapper/order_blob_splitter.rb', line 9

def initialize (input)
  input = StringIO.new(input) if input.class == String  # Used for testing.
  @stream = input
  @buy_item_lines = []
end

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/logbox/stream_wrapper/order_blob_splitter.rb', line 28

def eof?
  @stream.eof? 
end

#getsObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/logbox/stream_wrapper/order_blob_splitter.rb', line 15

def gets
  if @buy_item_lines.size > 0
    return @buy_item_lines.shift
  end
  
  line = @stream.gets
  if line && line.include?("&o=buy_basket&")
    extract_buy_items(line)
    line = reformat_buy_basket(line)
  end
  line
end