Sha256: f1bb5863c46447b3d7d9d7b97b0b5c432561919fabe9f393f3839c9c51557c0e

Contents?: true

Size: 1000 Bytes

Versions: 4

Compression:

Stored size: 1000 Bytes

Contents

require 'csv'

module Ddr::IngestTools::DdrRdrMigrator
  class ColumnRenamer

    attr_reader :logger
    attr_accessor :manifest

    HEADER_MAP = { 'permanent_id' => 'ark',
                   'date' => 'available',
                   'spatial' => 'based_near',
                   'type' => 'resource_type',
                   'relation' => 'related_url',
                   'rights' => 'license',
                   'bibliographicCitation' => 'bibliographic_citation'
                 }

    def initialize(logger: nil, manifest:)
      @logger = logger || Logger.new(STDOUT)
      @manifest = manifest
    end

    def call
      rename
    end

    private

    def rename
      csv_array = manifest.to_a
      csv_headers = csv_array[0]
      new_headers = csv_headers.map { |hdr| HEADER_MAP.fetch(hdr, hdr) }
      csv_array[0] = new_headers
      csv_string = CSV.generate { |csv_out| csv_array.each { |array| csv_out << array } }
      CSV.parse(csv_string, headers: true)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ddr-ingesttools-0.6.1 lib/ddr/ingesttools/ddr_rdr_migrator/column_renamer.rb
ddr-ingesttools-0.6.0 lib/ddr/ingesttools/ddr_rdr_migrator/column_renamer.rb
ddr-ingesttools-0.5.0 lib/ddr/ingesttools/ddr_rdr_migrator/column_renamer.rb
ddr-ingesttools-0.5.0.rc3 lib/ddr/ingesttools/ddr_rdr_migrator/column_renamer.rb