class AwsAuditor::GoogleSheet
Attributes
path[RW]
sheet[RW]
worksheet[RW]
Public Class Methods
create_sheet(title, path)
click to toggle source
returns a spreadsheet object
# File lib/aws_auditor/google_sheet.rb, line 29 def self.create_sheet(title, path) folder = go_to_collection(path) if path if folder spreadsheet = folder.files("title" => title, "title-exact" => true).first if spreadsheet return spreadsheet else file = first_or_create(title) folder.add(file) google.root_collection.remove(file) return folder.files("title" => title, "title-exact" => true).first end else first_or_create(title) end end
delete_all_rows(worksheet)
click to toggle source
# File lib/aws_auditor/google_sheet.rb, line 71 def self.delete_all_rows(worksheet) worksheet.list.each do |row| row.clear end worksheet.save worksheet end
first_or_create(title)
click to toggle source
# File lib/aws_auditor/google_sheet.rb, line 23 def self.first_or_create(title) spreadsheet = google.root_collection.files("title" => title, "title-exact" => true).first spreadsheet ? spreadsheet : google.create_spreadsheet(title) end
go_to_collection(directory)
click to toggle source
returns a collection object
# File lib/aws_auditor/google_sheet.rb, line 53 def self.go_to_collection(directory) if directory path = directory.split('/') go_to_subcollection(google.collection_by_title(path.first),path[1..-1]) end end
go_to_subcollection(base, subs)
click to toggle source
returns a collection object
# File lib/aws_auditor/google_sheet.rb, line 61 def self.go_to_subcollection(base, subs) puts "Folder doesn't exist in specified path" and exit if base.nil? if subs.empty? return base else base = base.subcollection_by_title(subs.first) go_to_subcollection(base,subs[1..-1]) end end
new(title, path, environment)
click to toggle source
# File lib/aws_auditor/google_sheet.rb, line 8 def initialize(title, path, environment) @sheet = self.class.create_sheet(title, path) @worksheet = self.class.worksheet(sheet, environment) end
worksheet(spreadsheet, title)
click to toggle source
returns a worksheet object
# File lib/aws_auditor/google_sheet.rb, line 47 def self.worksheet(spreadsheet, title) worksheet = spreadsheet.worksheet_by_title(title) worksheet ? delete_all_rows(worksheet) : spreadsheet.add_worksheet(title) end
Public Instance Methods
write_header(header)
click to toggle source
# File lib/aws_auditor/google_sheet.rb, line 13 def write_header(header) worksheet.list.keys = header.unshift('name') worksheet.save end
write_row(value_hash)
click to toggle source
# File lib/aws_auditor/google_sheet.rb, line 18 def write_row(value_hash) worksheet.list.push(value_hash) worksheet.save end