class GoogleDrive::Worksheet
Public Instance Methods
export_hash(hash, update: false, find_by: nil)
click to toggle source
# File lib/model_to_googlesheet/google_drive/worksheet.rb, line 4 def export_hash hash, update: false, find_by: nil update_keys(hash) if update #find by :id/:whatever and update if found, else append row = row_with_hash hash, find_by: find_by row ? row.update(hash) : list.push(hash) else #append list.push(hash) end end
row_with_hash(hash, find_by: nil)
click to toggle source
either returns first row with given condition true, or nil
# File lib/model_to_googlesheet/google_drive/worksheet.rb, line 19 def row_with_hash hash, find_by: nil row = list.find do |row| #GoogleDrive::ListRow row[find_by] == hash[find_by].to_s end end
Private Instance Methods
update_keys(hash)
click to toggle source
merge existing keys with the new ones. (doesn’t take additional request, since this request will preload other rows)
# File lib/model_to_googlesheet/google_drive/worksheet.rb, line 30 def update_keys hash old_keys = self.list.keys new_keys = (old_keys + hash.keys.map(&:to_s)).uniq self.list.keys = new_keys #we are updating the first row. end