Class: Turbot::Handlers::PreviewHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/turbot/handlers/preview_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot_name, api) ⇒ PreviewHandler

Returns a new instance of PreviewHandler.



6
7
8
9
10
11
# File 'lib/turbot/handlers/preview_handler.rb', line 6

def initialize(bot_name, api)
  @bot_name = bot_name
  @api = api
  @count = 0
  @batch = []
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



4
5
6
# File 'lib/turbot/handlers/preview_handler.rb', line 4

def count
  @count
end

Instance Method Details

#handle_valid_record(record, data_type) ⇒ Object

Implements TurbotRunner::BaseHandler#handle_valid_record.



14
15
16
17
18
19
20
21
# File 'lib/turbot/handlers/preview_handler.rb', line 14

def handle_valid_record(record, data_type)
  @count += 1
  STDOUT.write('.')
  @batch << record.merge(:data_type => data_type)
  if @count % 20 == 0
    submit_batch
  end
end

#submit_batchObject



23
24
25
26
27
# File 'lib/turbot/handlers/preview_handler.rb', line 23

def submit_batch
  result = @api.create_draft_data(@bot_name, @batch.to_json)
  @batch = []
  result
end