Skip to content

Commit

Permalink
Add comma before first unit date in main title only
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Jun 5, 2024
1 parent 38e23b0 commit 9e52808
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions lib/dul_arclight/traject/ead2_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,20 @@
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)
first_date = true
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
" " + c.text.strip
end
rv = +""
rv << "," if first_date
rv << if c['type'] == 'bulk'
" (majority within " + c.text.strip + ")"
else
" " + c.text.strip
end
first_date = false
rv
else
c.text
end
Expand All @@ -194,7 +199,7 @@
result = result.gsub(/\s+,/, ',') # remove leading whitespace before comma
result = result.gsub(/,(\s|,)*,/, ',') # reduce multiple commas and interior whitespace to single comma
result = result.gsub(/(,)(\S)/, '\1 \2') # add whitespace after comma
result = result.gsub(/^,\s?/, '') # remove leading comma
result = result.gsub(/^,\s*/, '') # remove leading comma
accumulator << result
end
to_field 'title_formatted_ssm' do |record, accumulator, context|
Expand All @@ -203,15 +208,20 @@
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
first_date = true
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
" " + c.to_s.strip
end
rv = +""
rv << "," if first_date
rv << if c['type'] == 'bulk'
" (majority within " + c.to_s.strip + ")"
else
" " + c.to_s.strip
end
first_date = false
rv
else
c.to_s
end
Expand All @@ -220,7 +230,7 @@
result = result.gsub(/\s+,/, ',') # remove leading whitespace before comma
result = result.gsub(/,(\s|,)*,/, ',') # reduce multiple commas and interior whitespace to single comma
result = result.gsub(/(,)(\S)/, '\1 \2') # add whitespace after comma
result = result.gsub(/^,\s?/, '') # remove leading comma
result = result.gsub(/^,\s*/, '') # remove leading comma
accumulator << result
end
to_field 'title_teim', extract_xpath('/ead/archdesc/did/unittitle[not(@type) or ( @type != "sort" )]')
Expand Down Expand Up @@ -586,7 +596,7 @@
result = result.gsub(/\s+,/, ',') # remove leading whitespace before comma
result = result.gsub(/,(\s|,)*,/, ',') # reduce multiple commas and interior whitespace to single comma
result = result.gsub(/(,)(\S)/, '\1 \2') # add whitespace after comma
result = result.gsub(/^,\s?/, '') # remove leading comma
result = result.gsub(/^,\s*/, '') # remove leading comma
accumulator << result
end
to_field 'title_formatted_ssm' do |record, accumulator, context|
Expand All @@ -612,7 +622,7 @@
result = result.gsub(/\s+,/, ',') # remove leading whitespace before comma
result = result.gsub(/,(\s|,)*,/, ',') # reduce multiple commas and interior whitespace to single comma
result = result.gsub(/(,)(\S)/, '\1 \2') # add whitespace after comma
result = result.gsub(/^,\s?/, '') # remove leading comma
result = result.gsub(/^,\s*/, '') # remove leading comma
accumulator << result
end
to_field 'title_teim', extract_xpath('./did/unittitle[not(@type) or ( @type != "sort" )]')
Expand Down

0 comments on commit 9e52808

Please sign in to comment.