Module: CsvRails::ActiveModel::InstanceMethods

Defined in:
lib/csv_rails/active_model.rb

Instance Method Summary collapse

Instance Method Details

#to_csv_ary(fields = nil, opts = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/csv_rails/active_model.rb', line 36

def to_csv_ary(fields=nil, opts={})
  fields = attribute_names unless fields
  fields.map{|field|
    field.to_s.split(".").inject(self){|object, f|
      next unless object
      convert_method = "#{f}_as_csv"
      method = object.respond_to?(convert_method) ? convert_method : f
      object.send(method)
    }
  }
end