Sha256: e4551a475b9333f55a42ef71abce794e4afff0d6d26a65bb0ed66277d46f8a15

Contents?: true

Size: 849 Bytes

Versions: 12

Compression:

Stored size: 849 Bytes

Contents

class Hash
  def write_excel(filename)
    generate_excel(filename) do |workbook|
      each do |sheet_name, sheet_data|
        workbook.add_worksheet(name: sheet_name) do |sheet|
          if sheet_data.is_a?(Hash) && sheet_data[:fields].present?
              fields = sheet_data[:fields].map(&:to_s)
            else
              fields = sheet_data[:data].first.attributes.keys
            end
            sheet.add_row(fields, types: [:string] * fields.size)
            sheet_data = sheet_data[:data]
          end
          sheet_data.each do |row|
            if row.is_a?(Array)
              sheet.add_row(row.map(&:to_s), types: [:string] * row.size)
            else
              sheet.add_row(row.slice(fields).values.map(&:to_s), types: [:string] * fields.size)
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
arql-0.2.11 lib/arql/ext/hash.rb
arql-0.2.10 lib/arql/ext/hash.rb
arql-0.2.9 lib/arql/ext/hash.rb
arql-0.2.8 lib/arql/ext/hash.rb
arql-0.2.7 lib/arql/ext/hash.rb
arql-0.2.6 lib/arql/ext/hash.rb
arql-0.2.5 lib/arql/ext/hash.rb
arql-0.2.4 lib/arql/ext/hash.rb
arql-0.2.3 lib/arql/ext/hash.rb
arql-0.2.2 lib/arql/ext/hash.rb
arql-0.2.1 lib/arql/ext/hash.rb
arql-0.2.0 lib/arql/ext/hash.rb