Class: FatFreeCRM::ExportCSV
- Inherits:
-
Object
- Object
- FatFreeCRM::ExportCSV
- Defined in:
- lib/fat_free_crm/export_csv.rb
Class Method Summary collapse
-
.from_array(items = []) ⇒ Object
CSV export.
Class Method Details
.from_array(items = []) ⇒ Object
CSV export. Based on to_csv Rails plugin by Ary Djmal github.com/arydjmal/to_csv
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fat_free_crm/export_csv.rb', line 15 def self.from_array(items = []) return '' if items.empty? # Infer column types from the first item in the array klass = items.first.class columns = klass.columns.map(&:name).reject { |column| column =~ /password|token/ } columns << 'tags' if klass.taggable? CSV.generate do |csv| csv << columns.map { |column| klass.human_attribute_name(column) } items.each do |item| csv << columns.map do |column| if column == 'tags' item..join(' ') else item.send(column) end end end end end |