Sha256: 32c3ce9275303b97d65801ea7954682a138f6a06249de1630997a3b29671e10e

Contents?: true

Size: 1.17 KB

Versions: 21

Compression:

Stored size: 1.17 KB

Contents

module Eco
  module API
    module Common
      module People
        class DefaultParsers
          class CSVParser < People::BaseParser

            def process
              @parsers.define_attribute(:csv, dependencies: @options) do |parser|
                parser.def_parser  do |data, deps|
                  arr_hash = []
                  CSV.parse(data, headers: true).each do |row|
                    row_hash = row.headers.uniq.each_with_object({}) do |attr, hash|
                      hash[attr] = row[attr]
                    end
                    arr_hash.push(row_hash)
                  end
                  arr_hash
                end.def_serializer do |array_hash, deps|
                  arr_rows = []
                  unless array_hash.empty?
                    header = array_hash.first.keys
                    arr_rows = array_hash.map do |csv_row|
                      CSV::Row.new(header, csv_row.values_at(*header))
                    end
                  end
                  CSV::Table.new(arr_rows).to_csv
                end
              end
            end

          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
eco-helpers-1.0.11 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-1.0.10 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-1.0.9 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-1.0.8 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-1.0.7 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-1.0.6 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-1.0.5 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-1.0.4 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-1.0.3 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.9.5 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-1.0.2 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.9.4 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.9.3 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.9.2 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.9.1 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.8.4 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.8.3 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.8.2 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.8.1 lib/eco/api/common/people/default_parsers/csv_parser.rb
eco-helpers-0.7.2 lib/eco/api/common/people/default_parsers/csv_parser.rb