Class: TableImporter::Google

Inherits:
RooSpreadsheetSource show all
Defined in:
lib/table_importer/google.rb

Constant Summary

Constants inherited from Source

Source::NIL_VALUES, Source::SEPARATORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RooSpreadsheetSource

#convert_headers, #get_chunks, #get_headers, #get_lines, #get_preview_lines

Methods inherited from Source

#clean_chunks, #default_headers, #get_chunks, #get_column_separator, #get_headers, #get_lines, #get_preview_lines, #get_record_separator, #get_sep_count, #sort_separators

Constructor Details

#initialize(data) ⇒ Google

Returns a new instance of Google.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/table_importer/google.rb', line 7

def initialize(data)
  begin
    @file = get_file(data[:content].split(", ")[1], data[:content].split(", ")[0])

    @headers_present    = data[:headers_present]
    @compulsory_headers = data[:compulsory_headers]
    @mapping            = data[:user_headers] if data[:user_headers].present?
    @remove_nil_values  = data[:remove_nil_values] == true

    @delete_empty_columns = false

    raise TableImporter::EmptyFileImportError.new if !@file.first_row

    @headers = @headers_present ? @file.row(1).map.with_index { |header, index| header.present? ? header.to_sym : "column_#{index}"} : default_headers
  rescue NoMethodError
    raise TableImporter::HeaderMismatchError.new
  end
end

Instance Attribute Details

#remove_nil_valuesObject

Returns the value of attribute remove_nil_values.



5
6
7
# File 'lib/table_importer/google.rb', line 5

def remove_nil_values
  @remove_nil_values
end

Instance Method Details

#get_file(file_key, access_token) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/table_importer/google.rb', line 26

def get_file(file_key, access_token)
  begin
    Roo::Google.new(file_key, { :access_token => access_token })
  rescue TypeError
    raise TableImporter::IncorrectFileError.new
  end
end

#get_typeObject



34
35
36
# File 'lib/table_importer/google.rb', line 34

def get_type
  "google"
end