Sha256: b8a54f1c7e4793e8c178ccf4e87ed01469e44fa1f22b8f59e3e8d9deb053cf06

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

module Ddr::IngestTools::DdrRdrMigrator
  class MetadataOverwriter

    attr_reader :logger, :manifest

    OVERWRITTEN_FIELDS = %w[ creator publisher available license ].freeze

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

    def call
      overwrite
      manifest
    end

    private

    def overwrite
      populate_overwriting_attributes
      overwrite_values
    end

    def collection_row
      @collection_row = manifest.find { |row| row['model'] == 'Collection' }
    end

    def item_rows
      manifest.select { |row| row['model'] == 'Item' }
    end

    def overwrite_values
      item_rows.each do |row|
        collection_overwriting_attributes.each do |field, value|
          row[field] = value
        end
      end
    end

    def collection_overwriting_attributes
      @overwriting_attributes ||= populate_overwriting_attributes
    end

    def populate_overwriting_attributes
      attrs = {}
      OVERWRITTEN_FIELDS.each do |field|
        attrs[field] = collection_row[field] if collection_row[field]
      end
      attrs
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ddr-ingesttools-0.6.1 lib/ddr/ingesttools/ddr_rdr_migrator/metadata_overwriter.rb
ddr-ingesttools-0.6.0 lib/ddr/ingesttools/ddr_rdr_migrator/metadata_overwriter.rb
ddr-ingesttools-0.5.0 lib/ddr/ingesttools/ddr_rdr_migrator/metadata_overwriter.rb
ddr-ingesttools-0.5.0.rc3 lib/ddr/ingesttools/ddr_rdr_migrator/metadata_overwriter.rb
ddr-ingesttools-0.5.0.rc2 lib/ddr/ingesttools/ddr_rdr_migrator/metadata_overwriter.rb
ddr-ingesttools-0.5.0.rc1 lib/ddr/ingesttools/ddr_rdr_migrator/metadata_overwriter.rb