Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supply title and repository as kwargs for local id forming requirements #1532

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/arclight/normalized_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
module Arclight
##
# A simple utility class to normalize identifiers
# to be used around the application for linking
class NormalizedId
def initialize(id)
# Accepts unused kwargs from the ead2_config.rb id to_field directive
# (:title and :repository) so that applications can provide a custom
# id_normalizer class to traject to form the collection id from these attributes.
def initialize(id, **_kwargs)
@id = id
end

Expand Down
10 changes: 9 additions & 1 deletion lib/arclight/traject/ead2_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'traject_plus'
require 'traject_plus/macros'
require 'arclight/level_label'
require 'arclight/normalized_id'
require 'arclight/normalized_date'
require 'arclight/normalized_title'
require 'active_model/conversion' ## Needed for Arclight::Repository
Expand Down Expand Up @@ -53,6 +54,7 @@

settings do
provide 'component_traject_config', File.join(__dir__, 'ead2_component_config.rb')
provide 'id_normalizer', 'Arclight::NormalizedId'
provide 'date_normalizer', 'Arclight::NormalizedDate'
provide 'title_normalizer', 'Arclight::NormalizedTitle'
provide 'reader_class_name', 'Arclight::Traject::NokogiriNamespacelessReader'
Expand All @@ -75,7 +77,13 @@
# NOTE: All fields should be stored in Solr
# ==================

to_field 'id', extract_xpath('/ead/eadheader/eadid'), strip, gsub('.', '-')
to_field 'id' do |record, accumulator|
id = record.at_xpath('/ead/eadheader/eadid')&.text
title = record.at_xpath('/ead/archdesc/did/unittitle')&.text
repository = settings['repository']
accumulator << settings['id_normalizer'].constantize.new(id, title: title, repository: repository).to_s
end

to_field 'title_filing_ssi', extract_xpath('/ead/eadheader/filedesc/titlestmt/titleproper[@type="filing"]')
to_field 'title_ssm', extract_xpath('/ead/archdesc/did/unittitle')
to_field 'title_tesim', extract_xpath('/ead/archdesc/did/unittitle')
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/arclight/normalized_id_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@
)
end
end

context 'when additional keyword arguments are supplied' do
subject(:normalized_id) { described_class.new('abc123.xml', title: 'a title', repository: 'repo').to_s }

it 'accepts the additional arguments without changing the output' do
expect(normalized_id).to eq 'abc123-xml'
end
end
end