Class: ActiveWorksheet::Adapters::GoogleSheetsAdapter
- Inherits:
-
BaseAdapter
- Object
- BaseAdapter
- ActiveWorksheet::Adapters::GoogleSheetsAdapter
- Defined in:
- lib/active_worksheet/adapters/google_sheets_adapter.rb
Constant Summary collapse
- ADAPTER_NAME =
"GoogleSheets"
Instance Attribute Summary
Attributes inherited from BaseAdapter
Instance Method Summary collapse
- #all ⇒ Object
- #count ⇒ Object
- #find(index) ⇒ Object
- #first ⇒ Object
-
#initialize(source: nil, authorization: {}) ⇒ GoogleSheetsAdapter
constructor
A new instance of GoogleSheetsAdapter.
- #last ⇒ Object
Methods inherited from BaseAdapter
Constructor Details
#initialize(source: nil, authorization: {}) ⇒ GoogleSheetsAdapter
Returns a new instance of GoogleSheetsAdapter.
10 11 12 |
# File 'lib/active_worksheet/adapters/google_sheets_adapter.rb', line 10 def initialize(source: nil, authorization: {}) super(source: source, authorization: ) end |
Instance Method Details
#all ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_worksheet/adapters/google_sheets_adapter.rb', line 14 def all session = build_session() @workbook = session.spreadsheet_by_url(source) table = @workbook.worksheets.first headers = table.rows[0].map do |header| ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.parameterize(header)) end table.rows(1).map do |row| row.each_with_index.reduce({}) do |result, (value, index)| result[headers[index]] = value result end end end |
#count ⇒ Object
43 44 45 |
# File 'lib/active_worksheet/adapters/google_sheets_adapter.rb', line 43 def count all.count end |
#find(index) ⇒ Object
31 32 33 |
# File 'lib/active_worksheet/adapters/google_sheets_adapter.rb', line 31 def find(index) all[index] end |
#first ⇒ Object
35 36 37 |
# File 'lib/active_worksheet/adapters/google_sheets_adapter.rb', line 35 def first find(0) end |
#last ⇒ Object
39 40 41 |
# File 'lib/active_worksheet/adapters/google_sheets_adapter.rb', line 39 def last find(-1) end |