Class: CSVPlusPlus::Reader::GoogleSheets
- Extended by:
- T::Generic, T::Sig
- Includes:
- GoogleApiClient
- Defined in:
- lib/csv_plus_plus/reader/google_sheets.rb
Overview
A class that can read an existing Google Sheets spreadsheet
Constant Summary collapse
- CellValue =
type_member { { fixed: ::String } }
Instance Method Summary collapse
-
#initialize(options) ⇒ GoogleSheets
constructor
Open a CSV outputter to the
output_filename
specified by theOptions
. - #sheet ⇒ Google::Apis::SheetsV4::Sheet?
- #spreadsheet ⇒ Google::Apis::SheetsV4::Spreadsheet
-
#value_at(cell) ⇒ CellValue?
Get the current value at the
cell
‘s location.
Methods included from GoogleApiClient
Constructor Details
#initialize(options) ⇒ GoogleSheets
Open a CSV outputter to the output_filename
specified by the Options
19 20 21 22 23 24 |
# File 'lib/csv_plus_plus/reader/google_sheets.rb', line 19 def initialize() super() @options = @cell_values = ::T.let(nil, ::T.nilable(::T::Array[::T::Array[::T.nilable(::String)]])) end |
Instance Method Details
#sheet ⇒ Google::Apis::SheetsV4::Sheet?
40 41 42 |
# File 'lib/csv_plus_plus/reader/google_sheets.rb', line 40 def sheet spreadsheet.sheets.find { |s| s.properties.title.strip == @options.sheet_name.strip } end |
#spreadsheet ⇒ Google::Apis::SheetsV4::Spreadsheet
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/csv_plus_plus/reader/google_sheets.rb', line 46 def spreadsheet @spreadsheet ||= ::T.let( sheets_client.get_spreadsheet(@options.sheet_id), ::T.nilable(::Google::Apis::SheetsV4::Spreadsheet) ) unless @spreadsheet raise(::CSVPlusPlus::Error::WriterError, "Unable to connect to google spreadsheet #{@options.sheet_id}") end @spreadsheet end |
#value_at(cell) ⇒ CellValue?
Get the current value at the cell
‘s location.
34 35 36 |
# File 'lib/csv_plus_plus/reader/google_sheets.rb', line 34 def value_at(cell) cell_values[cell.row_index]&.[](cell.index) end |