class Munchsrb::Exporter::Sheet
Munchsrb::Exporter::Sheet
exports content to Google Spread Sheet
.
Constants
- COLUMN_START_INDEX
- HEADER
- ROW_START_INDEX
Public Class Methods
new(key = nil)
click to toggle source
# File lib/munchsrb/exporter/sheet.rb, line 11 def initialize(key = nil) session = Munchsrb::Exporter::GoogleClient.session @worksheet = session.spreadsheet_by_key(ENV.fetch('GOOGLE_SPREAD_SHEET_KEY', key)).worksheets[0] end
Public Instance Methods
export(details)
click to toggle source
# File lib/munchsrb/exporter/sheet.rb, line 16 def export(details) contents = [] contents << HEADER details.each { |detail| contents << [detail[:name], detail[:price]] } save(contents) end
Private Instance Methods
save(contents)
click to toggle source
# File lib/munchsrb/exporter/sheet.rb, line 25 def save(contents) contents.each.with_index(ROW_START_INDEX) do |content, row_index| content.each.with_index(COLUMN_START_INDEX) do |c, column_index| @worksheet[row_index, column_index] = c end end @worksheet.save end