Sha256: 937ce808bda1ff4b204d90de31e6382ddf46bf1b13c77fd07a6fa539b4ca24b0

Contents?: true

Size: 786 Bytes

Versions: 4

Compression:

Stored size: 786 Bytes

Contents

module GSheets
  module V4
    class Sheet
      def initialize(sheet:, spread_sheet:)
        @sheet = sheet
        @spread_sheet = spread_sheet
        @session = spread_sheet.session
        @sheet_name = sheet.properties.title
      end

      def append(row)
        @session.append_row_to_spreadsheet(
          id: @spread_sheet.id,
          sheet_name: @sheet_name,
          row: row
        )
      end

      def rows
        all_rows = @session.get_spreadsheet_values(
          id: @spread_sheet.id,
          sheet_name: @sheet_name
        ).values

        headers = all_rows[0]
        all_rows.drop(1).map { |row|
          row_as_hash = {}
          headers.zip(row) { |k, v| row_as_hash[k] = v }
          Row.new(row_as_hash)
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
g_sheets-0.3.3 lib/g_sheets/v4/sheet.rb
g_sheets-0.3.2 lib/g_sheets/v4/sheet.rb
g_sheets-0.3.1 lib/g_sheets/v4/sheet.rb
g_sheets-0.3.0 lib/g_sheets/v4/sheet.rb