Class: SpreadsheetToJson::Spreadsheet

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadsheet_to_json/spreadsheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Spreadsheet

Initalize the spreadsheet with options hash inlcuding access_token and spreadsheet_key



7
8
9
10
11
12
13
14
15
# File 'lib/spreadsheet_to_json/spreadsheet.rb', line 7

def initialize(options = {})
  if options.empty?
    puts "Please pass the parameter options with keys 
      of access_token and spreadsheet_key"
    exit
  end
  session = GoogleDrive.(options[:access_token])
  @spreadsheet = session.spreadsheet_by_key(options[:spreadsheet_key])
end

Instance Attribute Details

#spreadsheetObject (readonly)

Returns the value of attribute spreadsheet.



5
6
7
# File 'lib/spreadsheet_to_json/spreadsheet.rb', line 5

def spreadsheet
  @spreadsheet
end

Instance Method Details

#get_sheet_by_id(worksheet_id = 0) ⇒ Object

Get a sheet by worksheet’s id



18
19
20
# File 'lib/spreadsheet_to_json/spreadsheet.rb', line 18

def get_sheet_by_id(worksheet_id=0)
  spreadsheet.worksheets[worksheet_id]
end

#get_sheet_by_name(worksheet_name) ⇒ Object

Get a sheet by a worksheet’s name



23
24
25
# File 'lib/spreadsheet_to_json/spreadsheet.rb', line 23

def get_sheet_by_name(worksheet_name)
  spreadsheet.worksheet_by_title(worksheet_name)
end