Skip to content

Commit

Permalink
Supply title and repository as kwargs for local id forming requiremen…
Browse files Browse the repository at this point in the history
…ts (#1532)
  • Loading branch information
corylown authored May 8, 2024
1 parent 8151234 commit 373ce44
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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

0 comments on commit 373ce44

Please sign in to comment.