module Csvgem
Constants
- VERSION
Public Class Methods
insert_columns(book, model, attributes = [])
click to toggle source
# File lib/csvgem.rb, line 14 def self.insert_columns(book, model, attributes = []) attributes = model.column_names if attributes.empty? sheet = book.create_worksheet(name: model.to_s.pluralize) attributes.each { |attribute| sheet.row(0).push(attribute) } model.all.each_with_index do |column, index| attributes.each do |attribute| sheet.row(index+1).push(column.attributes[attribute]) end end end
to_xls(*models)
click to toggle source
# File lib/csvgem.rb, line 25 def self.to_xls(*models) book = Spreadsheet::Workbook.new models.each do |model| Csvgem.insert_columns(book, model) end book.write "./records.xls" end