Module: SheetsV4::GoogleExtensions::Spreadsheet
- Included in:
- Google::Apis::SheetsV4::Spreadsheet
- Defined in:
- lib/sheets_v4/google_extensions/spreadsheet.rb
Overview
The SheetsService class implements handling credentials on top of the Google::Apis::SheetsV4::SheetsService class.
Instance Attribute Summary collapse
-
#sheets_service ⇒ Google::Apis::SheetsV4::SheetsService
readonly
The sheets_service object used to create this spreadsheet.
Instance Method Summary collapse
-
#each_sheet(ids_or_titles = sheets.map { |sheet| sheet.properties.sheet_id }) {|the| ... }
Iterate over sheets in a spreadsheet.
-
#sheet(id_or_title) ⇒ Google::Apis::SheetsV4::Sheet?
Return the matching sheet object or nil.
-
#sheet_id(id_or_title) ⇒ Integer
Return the ID of the matching sheet.
Instance Attribute Details
#sheets_service ⇒ Google::Apis::SheetsV4::SheetsService (readonly)
The sheets_service object used to create this spreadsheet
20 21 22 |
# File 'lib/sheets_v4/google_extensions/spreadsheet.rb', line 20 def sheets_service @sheets_service end |
Instance Method Details
#each_sheet(ids_or_titles = sheets.map { |sheet| sheet.properties.sheet_id }) {|the| ... }
This method returns an undefined value.
Iterate over sheets in a spreadsheet
If ids_or_titles
is not given or is nil, all sheets are enumerated. Otherwise,
only the sheets whose IDs or titles are in sheets
are enumerated.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sheets_v4/google_extensions/spreadsheet.rb', line 90 def each_sheet(ids_or_titles = sheets.map { |sheet| sheet.properties.sheet_id }, &block) return enum_for(:each_sheet, ids_or_titles) unless block matching_sheets = ids_or_titles.map do |id_or_title| sheet(id_or_title) || raise("Could not find sheet '#{id_or_title}'") end matching_sheets.each { |sheet| block[sheet] } self end |
#sheet(id_or_title) ⇒ Google::Apis::SheetsV4::Sheet?
Return the matching sheet object or nil
If id_or_title
is an Integer, it is assumed to be the sheet ID. Otherwise,
it is assumed to be the sheet title.
41 42 43 44 45 46 47 48 |
# File 'lib/sheets_v4/google_extensions/spreadsheet.rb', line 41 def sheet(id_or_title) if id_or_title.is_a?(Integer) sheets.find { |sheet| sheet.properties.sheet_id == id_or_title } else title = id_or_title.to_s sheets.find { |sheet| sheet.properties.title == title } end end |
#sheet_id(id_or_title) ⇒ Integer
Return the ID of the matching sheet
59 60 61 |
# File 'lib/sheets_v4/google_extensions/spreadsheet.rb', line 59 def sheet_id(id_or_title) sheet(id_or_title)&.properties&.sheet_id end |