lib/columnify/columnify_template.rb in columnify-0.1.0 vs lib/columnify/columnify_template.rb in columnify-0.1.1
- old
+ new
@@ -1,9 +1,10 @@
# frozen_string_literal: true
-require "action_dispatch/http/mime_type"
-require "spreadsheet"
+require 'action_dispatch/http/mime_type'
+require 'spreadsheet'
+require 'columnify/worksheet'
class ColumnifyTemplate
class << self
attr_accessor :template_lookup_options
end
@@ -13,34 +14,12 @@
def initialize(context, *args)
@context = context
super(*args)
end
- def workbook
- @workbook ||= Spreadsheet::Workbook.new
- end
-
def worksheet(resources, *args)
- sheet = workbook.create_worksheet(name: worksheet_name.to_s)
-
- sheet.row(0).concat args.map(&:to_s).map(&:humanize)
-
- resources.each_with_index do |resource, index|
- args.each do |method_name|
- sheet.row(index + 1).push(resource.send(method_name))
- end
- end
-
- buffer = StringIO.new
- workbook.write(buffer)
- buffer.rewind
- buffer.read
- end
-
- private
-
- def worksheet_name
- DateTime.now.to_i
+ worksheet = Columnify::Worksheet.new(resources, *args)
+ worksheet.create
end
end
class ColumnifyHandler
cattr_accessor :default_format