Class: C11n::External::GoogleDriveDriver
- Inherits:
-
Object
- Object
- C11n::External::GoogleDriveDriver
- Defined in:
- lib/c11n/external/google_drive_driver.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#password ⇒ Object
Returns the value of attribute password.
-
#spreadsheet_key ⇒ Object
Returns the value of attribute spreadsheet_key.
-
#worksheet_number ⇒ Object
Returns the value of attribute worksheet_number.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(options = {}) ⇒ GoogleDriveDriver
constructor
A new instance of GoogleDriveDriver.
- #load_configuration ⇒ Object
- #load_from_options(options) ⇒ Object
- #spreadsheet ⇒ Object
- #table ⇒ Object
- #worksheet ⇒ Object
- #write_table(table) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GoogleDriveDriver
Returns a new instance of GoogleDriveDriver.
8 9 10 11 |
# File 'lib/c11n/external/google_drive_driver.rb', line 8 def initialize( = {}) () load_configuration end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
6 7 8 |
# File 'lib/c11n/external/google_drive_driver.rb', line 6 def email @email end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/c11n/external/google_drive_driver.rb', line 6 def password @password end |
#spreadsheet_key ⇒ Object
Returns the value of attribute spreadsheet_key.
6 7 8 |
# File 'lib/c11n/external/google_drive_driver.rb', line 6 def spreadsheet_key @spreadsheet_key end |
#worksheet_number ⇒ Object
Returns the value of attribute worksheet_number.
6 7 8 |
# File 'lib/c11n/external/google_drive_driver.rb', line 6 def worksheet_number @worksheet_number end |
Instance Method Details
#connection ⇒ Object
27 28 29 |
# File 'lib/c11n/external/google_drive_driver.rb', line 27 def connection @connection ||= ::GoogleDrive.login(@email, @password) end |
#load_configuration ⇒ Object
20 21 22 23 24 25 |
# File 'lib/c11n/external/google_drive_driver.rb', line 20 def load_configuration @email ||= C11n::Configuration.instance.external(:google_drive)[:email] @password ||= C11n::Configuration.instance.external(:google_drive)[:password] @spreadsheet_key ||= C11n::Configuration.instance.external(:google_drive)[:spreadsheet_key] @worksheet_number ||= C11n::Configuration.instance.external(:google_drive)[:worksheet_number] end |
#load_from_options(options) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/c11n/external/google_drive_driver.rb', line 13 def () @email = [:email] @password = [:password] @spreadsheet_key = [:spreadsheet_key] @worksheet_number = [:worksheet_number] end |
#spreadsheet ⇒ Object
35 36 37 |
# File 'lib/c11n/external/google_drive_driver.rb', line 35 def spreadsheet @spreadsheet ||= connection.spreadsheet_by_key(@spreadsheet_key) end |
#table ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/c11n/external/google_drive_driver.rb', line 39 def table raw_table = [] for row in 1..worksheet.num_rows raw_table[row - 1] ||= [] for col in 1..worksheet.num_cols raw_table[row - 1][col - 1] ||= worksheet[row, col] end end raw_table end |
#worksheet ⇒ Object
31 32 33 |
# File 'lib/c11n/external/google_drive_driver.rb', line 31 def worksheet @worksheet ||= spreadsheet.worksheets[@worksheet_number] end |
#write_table(table) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/c11n/external/google_drive_driver.rb', line 53 def write_table(table) table.each_with_index do |row, row_index| row.each_with_index do |column, column_index| worksheet[row_index + 1, column_index + 1] = column if column end end worksheet.save end |