Class: PredictionIO::FileExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/predictionio/file_exporter.rb

Overview

This class contains methods that allow you to export data for import though:

$ pio import FILENAME

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FileExporter

Returns a new instance of FileExporter


23
24
25
26
# File 'lib/predictionio/file_exporter.rb', line 23

def initialize(filename)
  @filename = filename
  @file = File.open(@filename, 'w')
end

Instance Method Details

#closeObject


40
41
42
# File 'lib/predictionio/file_exporter.rb', line 40

def close
  @file.close
end

#create_event(event, entity_type, entity_id, optional = {}) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/predictionio/file_exporter.rb', line 28

def create_event(event, entity_type, entity_id, optional = {})

  h = optional
  h.key?('eventTime') || h['eventTime'] = DateTime.now.to_s
  h['event'] = event
  h['entityType'] = entity_type
  h['entityId'] = entity_id

  json = h.to_json
  @file.write("#{json}\n")
end