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.



8
9
10
11
# File 'lib/predictionio/file_exporter.rb', line 8

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

Instance Method Details

#closeObject



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

def close
  @file.close
end

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



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/predictionio/file_exporter.rb', line 13

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