Class: Cartoset::FeaturesDataImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/cartoset/features_data_importer.rb

Constant Summary collapse

DATA_FILE_PATH =
Rails.root.join('tmp/features_data.csv').freeze

Class Method Summary collapse

Class Method Details

.start(data_stream) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cartoset/features_data_importer.rb', line 5

def self.start(data_stream)
  table = {}
  File.open(DATA_FILE_PATH, 'w+') do |file|
    file.write(data_stream.read.force_encoding("UTF-8"))

    @tables = CartoDB::Connection.tables || nil
    CartoDB::Connection.drop_table('cartoset_features') if @tables && @tables.tables && @tables.tables.map{|t| t.name}.include?('cartoset_features')

    require 'ruby-debug'; debugger
    table = CartoDB::Connection.create_table 'cartoset_features', file
    table = CartoDB::Connection.table table.name
  end

  table
end