Sha256: 1d8bc8db055f2cd442614072e5595f3c42758de158888eb23f3144badf006723

Contents?: true

Size: 1.45 KB

Versions: 10

Compression:

Stored size: 1.45 KB

Contents

# Customizing metadata import

Often the data you will want to import will not conform exactly to the fields you get from `Hyrax::BasicMetadata`, in which case you will need to make a custom mapper.

Again, let's start with making a test. Make a file called `spec/importers/custom_mapper.rb`. Let's start by describing the CSV we expect to import:

```ruby
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe CustomMapper do
  subject(:mapper) { described_class.new }

  let(:metadata) do
    { "Name.architect" => "Imhotep", # architect
      "Type.genre" => "Journalism" # genre
    }

    describe '#fields' do
    it 'has expected fields' do
      expect(mapper.fields).to include(
        :architect,
        :genre
      )
    end
  end
```
From this rspec test, I can conclude that I have two customized metadata fields, `architect` and `genre`. Actually adding custom metadata fields is covered elsewhere (See [this guide](https://samvera.github.io/customize-metadata-generate-work-type.html), for example), so here we are just going to assume that these fields exist already, and are defined as multi-valued strings.


* Put a file in `config/initializers/zizia.rb`

It should look like this:

```ruby
Zizia.config do |config|
  config.metadata_mapper_class = CustomMapper
  config.default_info_stream = Rails.logger
  config.default_error_stream = Rails.logger
end
```
This tells zizia what class to use for metadata mappings, and where to log the output.

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
zizia-2.1.0.alpha.09 docs/customizing_metadata.md
zizia-2.1.0.alpha.08 docs/customizing_metadata.md
zizia-2.1.0.alpha.07 docs/customizing_metadata.md
zizia-2.1.0.alpha.06 docs/customizing_metadata.md
zizia-2.1.0.alpha.05 docs/customizing_metadata.md
zizia-2.1.0.alpha.04 docs/customizing_metadata.md
zizia-2.1.0.alpha.03 docs/customizing_metadata.md
zizia-2.1.0.alpha.02 docs/customizing_metadata.md
zizia-2.1.0.alpha.01 docs/customizing_metadata.md
zizia-2.0.0.alpha.01 docs/customizing_metadata.md