lib/to_xls.rb in bc-to_xls-0.0.0 vs lib/to_xls.rb in bc-to_xls-0.0.1
- old
+ new
@@ -2,12 +2,12 @@
def to_xls(options = {})
output = '<?xml version="1.0" encoding="UTF-8"?><Workbook xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office"><Worksheet ss:Name="Sheet1"><Table>'
if self.any?
-
- attributes = self.first.attributes.keys.map { |c| c.to_sym }
+ instance = self.first
+ attributes = instance.attributes.keys.map { |c| c.to_sym }
if options[:only]
# the "& attributes" get rid of invalid columns
columns = options[:only].to_a & attributes
else
@@ -17,10 +17,10 @@
columns += options[:methods].to_a
if columns.any?
unless options[:headers] == false
output << "<Row>"
- columns.each { |column| output << "<Cell><Data ss:Type=\"String\">#{self.class.human_attribute_name(column)}</Data></Cell>" }
+ columns.each { |column| output << "<Cell><Data ss:Type=\"String\">#{instance.class.human_attribute_name(column)}</Data></Cell>" }
output << "</Row>"
end
self.each do |item|
output << "<Row>"