Sha256: eaf95033a5eb778fda9fab0902a89b7dfd116352347b4b6ffc95221fd81eac21
Contents?: true
Size: 987 Bytes
Versions: 2
Compression:
Stored size: 987 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', 'citation' => '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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ddr-ingesttools-0.5.0.rc2 | lib/ddr/ingesttools/ddr_rdr_migrator/column_renamer.rb |
ddr-ingesttools-0.5.0.rc1 | lib/ddr/ingesttools/ddr_rdr_migrator/column_renamer.rb |