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 6dcad40 commit 56e105d
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 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,19 @@
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
first_date = false
rv << if c['type'] == 'bulk'
" (majority within " + c.text.strip + ")"
else
" " + c.text.strip
end
else
c.text
end
Expand All @@ -194,7 +198,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 +207,19 @@
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
first_date = false
rv << if c['type'] == 'bulk'
" (majority within " + c.to_s.strip + ")"
else
" " + c.to_s.strip
end
else
c.to_s
end
Expand All @@ -220,7 +228,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 +594,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 +620,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 56e105d

Please sign in to comment.