Class: TableImporter::Google
- Inherits:
-
RooSpreadsheetSource
- Object
- Source
- RooSpreadsheetSource
- TableImporter::Google
- Defined in:
- lib/table_importer/google.rb
Constant Summary
Constants inherited from Source
Instance Method Summary collapse
- #get_file(file_key, access_token) ⇒ Object
- #get_type ⇒ Object
-
#initialize(data) ⇒ Google
constructor
A new instance of Google.
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.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/table_importer/google.rb', line 5 def initialize(data) begin @headers_present = data[:headers_present] @file = get_file(data[:content].split(", ")[1], data[:content].split(", ")[0]) @compulsory_headers = data[:compulsory_headers] @delete_empty_columns = false @mapping = data[:user_headers] if data[:user_headers].present? 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 Method Details
#get_file(file_key, access_token) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/table_importer/google.rb', line 19 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_type ⇒ Object
27 28 29 |
# File 'lib/table_importer/google.rb', line 27 def get_type "google" end |