Skip to content

Commit

Permalink
Merge pull request #1425 from emory-libraries/new-fields-hotfix
Browse files Browse the repository at this point in the history
fixes bugs for 5xx, 7xx, 8xx fields
  • Loading branch information
CB987 authored Aug 28, 2024
2 parents aef29c3 + 7b340be commit d313101
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 68 deletions.
54 changes: 43 additions & 11 deletions app/helpers/catalog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,8 @@ def author_additional_collapse_span(values)
end

def multilined_links_to_facet_author_addl(values)
ret_vals = values.map do |v|
line_pieces = v.split(' relator: ')
quer_disp = line_pieces[0]
relator = line_pieces.size == 2 ? line_pieces[1] : nil

ret_line = link_to(quer_disp, ("/?f%5Bauthor_addl_ssim%5D%5B%5D=" + CGI.escape(quer_disp))).to_s
ret_line += ", #{relator}" if relator.present?
ret_line
end
return safe_join(ret_vals, tag.br) if ret_vals.present?
''
ret_vals = values.map { |v| process_value(v) }
ret_vals.present? ? safe_join(ret_vals, tag.br) : ''
end

def multilined_links_to_facet_flexible(values, field_name)
Expand All @@ -131,3 +122,44 @@ def build_title_search_links(record_values, record_formats)
end
end
end

private

def process_value(value)
line_pieces = split_value(value)
rest_of_line, relator = process_line_pieces(line_pieces)
quer_disp, prefix = process_rest_of_line(rest_of_line)

build_line(quer_disp, prefix, relator)
end

def split_value(value)
value.split(' relator: ')
end

def process_line_pieces(line_pieces)
rest_of_line = line_pieces[0].split(':')
relator = line_pieces.size == 2 ? content_tag(:span, ", " + line_pieces[1].strip) : nil
[rest_of_line, relator]
end

def process_rest_of_line(rest_of_line)
if rest_of_line.size == 2
quer_disp = rest_of_line[1].strip
prefix = content_tag(:span, rest_of_line[0].strip + ": ")
else
quer_disp = rest_of_line[0].strip
prefix = nil
end
[quer_disp, prefix]
end

def build_line(quer_disp, prefix, relator)
ret_line = prefix ? prefix + content_tag(:a, quer_disp, href: query_href(quer_disp)) : content_tag(:a, quer_disp, href: query_href(quer_disp))
ret_line += relator if relator.present?
ret_line
end

def query_href(quer_disp)
"/?f%5Bauthor_addl_ssim%5D%5B%5D=#{CGI.escape(quer_disp)}"
end
69 changes: 25 additions & 44 deletions lib/traject/extract_3a_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,84 +6,65 @@ module Extract3aFields
def extract_3a_fields(tag)
lambda do |record, accumulator|
record.each_by_tag(tag) do |field|
three_subfield = field['3']
a_subfield = field['a']

next unless three_subfield
three_subfield += ':' unless three_subfield.end_with?(':')
note = three_subfield
note += " #{a_subfield}" if a_subfield
accumulator << note
note = extractor_subfield3(field)
note += note.empty? ? a_subfield.to_s : " #{a_subfield}" if a_subfield

accumulator << note.strip unless note.strip.empty?
end
end
end

def extract_541_subfields_with_colon
lambda do |record, accumulator|
record.each_by_tag('541') do |field|
three_subfield = field['3']
c_subfield = field['c']
a_subfield = field['a']

next unless three_subfield

three_subfield += ':' unless three_subfield.end_with?(':')
note = extractor_subfield3(field)
note += note.empty? ? a_subfield.to_s : " #{a_subfield}" if a_subfield
note += note.empty? ? c_subfield.to_s : " #{c_subfield}" if c_subfield

note = three_subfield
note += " #{c_subfield}" if c_subfield
note += " #{a_subfield}" if a_subfield

accumulator << note
accumulator << note.strip unless note.strip.empty?
end
end
end

def extract_540_subfields
lambda do |record, accumulator|
record.each_by_tag('540') do |field|
three_subfield = field['3']
a_subfield = field['a']
f_subfield = field['f']
u_subfield = field['u']

next unless three_subfield
three_subfield += ':' unless three_subfield.end_with?(':')
note = [three_subfield, a_subfield, f_subfield, u_subfield].compact.join(' ')
accumulator << note
end
end
end

def extract_7xx_8xx_with_subfield3(tag)
lambda do |record, accumulator|
record.each_by_tag(tag) do |field|
three_subfield = field['3']
next unless three_subfield

three_subfield += ':' unless three_subfield.end_with?(':')
note = extractor_subfield3(field)
note += note.empty? ? a_subfield.to_s : " #{a_subfield}" if a_subfield
note += note.empty? ? f_subfield.to_s : " #{f_subfield}" if f_subfield
note += note.empty? ? u_subfield.to_s : " #{u_subfield}" if u_subfield

rest_of_field = field.map { |sf| sf.value.to_s unless sf.code == '3' }.compact.join(' ')
note = "#{three_subfield} #{rest_of_field}"

accumulator << note
accumulator << note.strip unless note.strip.empty?
end
end
end

def extract_8xx_with_subfield3(atog)
lambda do |record, accumulator|
record.fields(['800', '810', '811']).each do |field|
subfield3 = field['3']

subfield3 += ':' if subfield3 && !subfield3.end_with?(':')
note = extractor_subfield3(field)
subfields_to_extract = title_series_8xx_str(atog).split(':').find { |s| s.start_with?(field.tag) }
other_subfields = field.subfields.select { |sf| subfields_to_extract.include?(sf.code) }
.map(&:value)
.join(' ')

full_string = subfield3 ? "#{subfield3} #{other_subfields}".strip : other_subfields.strip
accumulator << full_string unless full_string.empty?
subfields_to_extract = subfields_to_extract[3..-1] if subfields_to_extract
other_subfields = field.subfields.select { |sf| subfields_to_extract.include?(sf.code) && sf.code != '3' }.map(&:value).join(' ')
note += note.empty? ? other_subfields : " #{other_subfields}" if other_subfields.present?
accumulator << note.strip unless note.strip.empty?
end
end
end
end

private

def extractor_subfield3(field)
subfield3 = field['3']
subfield3 ? subfield3.chomp(':') + ':' : ''
end
7 changes: 2 additions & 5 deletions lib/traject/extract_author_addl_display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ def build_ret_strings(record, field_num, text_fields, relator_field, ret_values)
end

def gather_subfield_three(field)
subfield_three = field['3']
return '' unless subfield_three

subfield_three = subfield_three.end_with?(':') ? subfield_three : "#{subfield_three}:"
"#{subfield_three} "
subfield3 = field['3']
subfield3 ? subfield3.chomp(':') + ':' : ''
end

def gather_relator_string(field, relator_field)
Expand Down
38 changes: 30 additions & 8 deletions spec/helpers/catalog_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,25 @@
dupe[:value] = ["Tim Jenkins relator: editor."]
dupe
end
let(:value_with_prefix) do
dupe = SHOW_PAGE_VALUE.dup
dupe[:value] = ["Prefix: Tim Jenkins"]
dupe
end
let(:value_with_prefix_relator) do
dupe = SHOW_PAGE_VALUE.dup
dupe[:value] = ["Prefix: Tim Jenkins relator: editor."]
dupe
end
let(:value_with_6_auth_addl) do
dupe = SHOW_PAGE_VALUE.dup
dupe[:value] = [
"Tim Jenkins relator: editor.",
"Sally Jenkins",
"Prefix: Tim Jenkins relator: editor.",
"Prefix: Sally Jenkins",
"Betsy Jenkins",
"Sal Weitzman relator: ghost writer.",
"Mike Birbiglia",
"Tim Conway relator: moral support."
"Tim Conway"
]
dupe
end
Expand All @@ -77,19 +87,31 @@

it 'converts a single valued additional author with relator into a facet search hyperlink, leaving relator out of the link' do
expect(helper.author_additional_format(value_with_relator)).to eq(
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Tim+Jenkins\">Tim Jenkins</a>, editor."
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Tim+Jenkins\">Tim Jenkins</a><span>, editor.</span>"
)
end

it 'converts a single valued additional author with prefix and relator into a facet search hyperlink, leaving relator and prefix out of the link' do
expect(helper.author_additional_format(value_with_prefix_relator)).to eq(
"<span>Prefix: </span><a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Tim+Jenkins\">Tim Jenkins</a><span>, editor.</span>"
)
end

it 'converts a single valued additional author with prefix into a facet search hyperlink, leaving prefix out of the link' do
expect(helper.author_additional_format(value_with_prefix)).to eq(
"<span>Prefix: </span><a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Tim+Jenkins\">Tim Jenkins</a>"
)
end

it 'converts a values array with more than 5 items into a new-lined list with a collapsible after 5' do # rubocop:disable RSpec/ExampleLength
expect(helper.author_additional_format(value_with_6_auth_addl)).to eq(
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Tim+Jenkins\">Tim Jenkins</a>, editor.<br>" \
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Sally+Jenkins\">Sally Jenkins</a><br>" \
"<span>Prefix: </span><a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Tim+Jenkins\">Tim Jenkins</a><span>, editor.</span><br>" \
"<span>Prefix: </span><a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Sally+Jenkins\">Sally Jenkins</a><br>" \
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Betsy+Jenkins\">Betsy Jenkins</a><br>" \
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Sal+Weitzman\">Sal Weitzman</a>, ghost writer.<br>" \
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Sal+Weitzman\">Sal Weitzman</a><span>, ghost writer.</span><br>" \
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Mike+Birbiglia\">Mike Birbiglia</a><br>" \
"<span id=\"extended-author-addl\" class=\"collapse collapsible-addl-authors\">" \
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Tim+Conway\">Tim Conway</a>, moral support.</span><br>" \
"<a href=\"/?f%5Bauthor_addl_ssim%5D%5B%5D=Tim+Conway\">Tim Conway</a></span><br>" \
"<a class=\"btn btn-link additional-authors-collapse collapsed\" data-toggle=\"collapse\"" \
" role=\"button\" aria-expanded=\"false\" aria-controls=\"extended-author-addl\" href=\"#extended-author-addl\"></a>"
)
Expand Down

0 comments on commit d313101

Please sign in to comment.