Skip to content

Commit

Permalink
Append date when not in title
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed May 29, 2024
1 parent c7e6375 commit fd72d94
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
13 changes: 8 additions & 5 deletions lib/dul_arclight/normalized_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ module Arclight
class NormalizedTitle
# @param [String] `title` from the `unittitle`
# @param [String] `date` from the `unitdate`
def initialize(title, date = nil)
def initialize(title, date = nil, append = true)
# @title = title.gsub(/\s*,\s*$/, '').strip if title.present?
@title = title.strip if title.present?
@date = date.strip if date.present?
@append = append
end

# @return [String] the normalized title/date
Expand All @@ -20,12 +21,14 @@ def to_s

private

attr_reader :title, :date
attr_reader :title, :date, :append

def normalize
# result = [title, date].compact.join(', ')
result = title
result = date if title.blank?
result = if append
[title, date].compact.join(', ')
else
title || date
end
raise Arclight::Exceptions::TitleNotFound if result.blank?

result
Expand Down
32 changes: 20 additions & 12 deletions lib/dul_arclight/traject/ead2_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,16 @@
# end

to_field 'title_filing_si', extract_xpath('/ead/eadheader/filedesc/titlestmt/titleproper[@type="filing"]')
to_field 'title_ssm' do |record, accumulator|
result = String.new
to_field 'title_ssm' do |record, accumulator, context|
context.clipboard[:title_ssm] = true
result = +''
nodeset = record.xpath('/ead/archdesc/did/unittitle[not(@type) or ( @type != "sort" )]')
nodeset.each do |n|
# n.xpath('child::node()[not(self::unitdate)]').map(&:text)
n.children.each do |c|
result << case c.name
when 'unitdate'
context.clipboard[:title_ssm] = false
if c['type'] == 'bulk'
", (majority within " + c.text.strip + ")"
else
Expand All @@ -199,14 +201,16 @@
result = result.gsub(/^,\s/, '') # remove leading comma
accumulator << result
end
to_field 'title_formatted_ssm' do |record, accumulator|
result = String.new
to_field 'title_formatted_ssm' do |record, accumulator, context|
context.clipboard[:title_formatted_ssm] = true
result = +''
nodeset = record.xpath('/ead/archdesc/did/unittitle[not(@type) or ( @type != "sort" )]')
nodeset.each do |n|
# n.xpath('child::node()[not(self::unitdate)]').to_s
n.children.each do |c|
result << case c.name
when 'unitdate'
context.clipboard[:title_formatted_ssm] = false
if c['type'] == 'bulk'
", (majority within " + c.to_s.strip + ")"
else
Expand Down Expand Up @@ -282,14 +286,14 @@
to_field 'normalized_title_ssm' do |_record, accumulator, context|
date = context.output_hash['normalized_date_ssm']&.first
title = context.output_hash['title_ssm']&.first
accumulator << Arclight::NormalizedTitle.new(title, date).to_s
accumulator << Arclight::NormalizedTitle.new(title, date, context.clipboard[:title_ssm]).to_s
end

# DUL CUSTOMIZATION: preserve formatting tags in titles
to_field 'normalized_title_formatted_ssm' do |_record, accumulator, context|
date = context.output_hash['normalized_date_ssm']&.first
title = context.output_hash['title_formatted_ssm']&.first.to_s
accumulator << Arclight::NormalizedTitle.new(title, date).to_s
accumulator << Arclight::NormalizedTitle.new(title, date, context.clipboard[:title_formatted_ssm]).to_s
end

to_field 'collection_ssm' do |_record, accumulator, context|
Expand Down Expand Up @@ -567,14 +571,16 @@
end

to_field 'title_filing_si', extract_xpath('./did/unittitle[not(@type) or ( @type != "sort" )]'), first_only
to_field 'title_ssm' do |record, accumulator|
result = String.new
to_field 'title_ssm' do |record, accumulator, context|
context.clipboard[:title_ssm] = true
result = +''
nodeset = record.xpath('./did/unittitle[not(@type) or ( @type != "sort" )]')
nodeset.each do |n|
# n.xpath('child::node()[not(self::unitdate)]').map(&:text)
n.children.each do |c|
result << case c.name
when 'unitdate'
context.clipboard[:title_ssm] = false
if c['type'] == 'bulk'
"(majority within " + c.text.strip + ")"
else
Expand All @@ -595,14 +601,16 @@
result = result.gsub(/^,\s/, '') # remove leading comma
accumulator << result
end
to_field 'title_formatted_ssm' do |record, accumulator|
result = String.new
to_field 'title_formatted_ssm' do |record, accumulator, context|
context.clipboard[:title_formatted_ssm] = true
result = +''
nodeset = record.xpath('./did/unittitle[not(@type) or ( @type != "sort" )]')
nodeset.each do |n|
# n.xpath('child::node()[not(self::unitdate)]').to_s
n.children.each do |c|
result << case c.name
when 'unitdate'
context.clipboard[:title_formatted_ssm] = false
if c['type'] == 'bulk'
"(majority within " + c.to_s.strip + ")"
else
Expand Down Expand Up @@ -642,14 +650,14 @@
to_field 'normalized_title_ssm' do |_record, accumulator, context|
date = context.output_hash['normalized_date_ssm']&.first
title = context.output_hash['title_ssm']&.first
accumulator << Arclight::NormalizedTitle.new(title, date).to_s
accumulator << Arclight::NormalizedTitle.new(title, date, context.clipboard[:title_ssm]).to_s
end

# DUL CUSTOMIZATION: use DUL rules for NormalizedDate
to_field 'normalized_title_formatted_ssm' do |_record, accumulator, context|
date = context.output_hash['normalized_date_ssm']&.first
title = context.output_hash['title_formatted_ssm']&.first.to_s
accumulator << Arclight::NormalizedTitle.new(title, date).to_s
accumulator << Arclight::NormalizedTitle.new(title, date, context.clipboard[:title_formatted_ssm]).to_s
end

# Aleph ID (esp. for request integration)
Expand Down

0 comments on commit fd72d94

Please sign in to comment.