Class: GoogleDrive::Worksheet
- Inherits:
-
Object
- Object
- GoogleDrive::Worksheet
- Defined in:
- lib/model_to_googlesheet/google_drive/worksheet.rb
Instance Method Summary collapse
- #export_hash(hash, update: false, find_by: nil) ⇒ Object
-
#row_with_hash(hash, find_by: nil) ⇒ Object
either returns first row with given condition true, or nil.
Instance Method Details
#export_hash(hash, update: false, find_by: nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# 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) ⇒ Object
either returns first row with given condition true, or nil
19 20 21 22 23 |
# 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 |