Skip to content

Commit

Permalink
Use any a-z subfield for summary holdings information (#376)
Browse files Browse the repository at this point in the history
866, 867, and 868 fields have summary holdings information in subfields
other than just |a, so we need to index all these subfields.
  • Loading branch information
awead authored Dec 8, 2021
1 parent ec430cb commit 7963d70
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 23 deletions.
20 changes: 17 additions & 3 deletions lib/psulib_traject/periodical_holdings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,29 @@ def add_summary(field)
end

def summary
@summaries.map { |field| field['a'] }
@summaries
.map { |field| atoz(field) }
.flatten
end

def add_supplement(field)
@supplementals << field
end

def supplement
@supplementals.map { |field| field['a'] }
@supplementals
.map { |field| atoz(field) }
.flatten
end

def add_index(field)
@indices << field
end

def index
@indices.map { |field| field['a'] }
@indices
.map { |field| atoz(field) }
.flatten
end

def to_hash
Expand All @@ -76,5 +82,13 @@ def summary_data
index: index
}
end

private

def atoz(field)
('a'..'z')
.map { |indicator| field[indicator] }
.compact
end
end
end
85 changes: 65 additions & 20 deletions spec/lib/psulib_traject/periodical_holdings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,91 @@
end

describe '#summary' do
before { holdings.add_summary(MARC::DataField.new('266', '0', '0', ['a', 'v.12(1956/57)-v.40:1-7/8(1984)'])) }
before do
holdings.add_summary(
MARC::DataField.new(
'266', '0', '0',
['a', 'v.12(1956/57)-v.40:1-7/8(1984)'],
['b', 'extra summary statement b'],
['c', 'extra summary statement c'],
['z', 'extra summary statement z']
)
)
end

its(:summary) { is_expected.to contain_exactly('v.12(1956/57)-v.40:1-7/8(1984)') }
its(:summary) { is_expected.to contain_exactly(
'v.12(1956/57)-v.40:1-7/8(1984)',
'extra summary statement b',
'extra summary statement c',
'extra summary statement z'
)}
end

describe '#supplement' do
before { holdings.add_supplement(MARC::DataField.new('267', '0', '0', ['a', 'supplement statement'])) }
before do
holdings.add_supplement(
MARC::DataField.new(
'267', '0', '0',
['a', 'supplement statement'],
['b', 'extra supplement statement b'],
['c', 'extra supplement statement c'],
['z', 'extra supplement statement z']
)
)
end

its(:supplement) { is_expected.to contain_exactly('supplement statement') }
its(:supplement) { is_expected.to contain_exactly(
'supplement statement',
'extra supplement statement b',
'extra supplement statement c',
'extra supplement statement z'
)}
end

describe '#index' do
before { holdings.add_index(MARC::DataField.new('268', '0', '0', ['a', 'index statement'])) }
before do
holdings.add_index(
MARC::DataField.new(
'268', '0', '0',
['a', 'index statement'],
['b', 'extra index statement b'],
['c', 'extra index statement c'],
['z', 'extra index statement z']
)
)
end

its(:index) { is_expected.to contain_exactly('index statement') }
its(:index) { is_expected.to contain_exactly(
'index statement',
'extra index statement b',
'extra index statement c',
'extra index statement z'
)}
end

describe '#to_hash' do
# @note Since DataField is just a kind of hash, we're using that for simplicity
before do
holdings.heading = { 'b' => 'Library', 'c' => 'Location', 'h' => 'Call Number' }
holdings.add_summary({ 'a' => 'The First Summary' })
holdings.add_summary({ 'a' => 'The Second Summary' })
holdings.add_supplement({ 'a' => 'The First Supplement' })
holdings.add_supplement({ 'a' => 'The Second Supplement' })
holdings.add_index({ 'a' => 'The First Index' })
holdings.add_index({ 'a' => 'The Second Index' })
end

let(:record) { MarcBot.build(:sample_summary_holdings) }
let(:sample) do
{
library: 'Library',
location: 'Location',
call_number: 'Call Number',
summary: ['The First Summary', 'The Second Summary'],
supplement: ['The First Supplement', 'The Second Supplement'],
index: ['The First Index', 'The Second Index']
summary: ['the first summary', 'extra summary 1', 'the second summary', 'extra summary 2'],
supplement: ['the first supplement', 'extra supplement 1', 'the second supplement', 'extra supplement 2'],
index: ['the first index', 'extra index 1', 'the second index', 'extra index 2']
}
end

before do
holdings.heading = record['852']
holdings.add_summary(record.fields('866')[0])
holdings.add_summary(record.fields('866')[1])
holdings.add_supplement(record.fields('867')[0])
holdings.add_supplement(record.fields('867')[1])
holdings.add_index(record.fields('868')[0])
holdings.add_index(record.fields('868')[1])
end

its(:to_hash) { is_expected.to eq(sample) }
end
end
25 changes: 25 additions & 0 deletions spec/records/summary_holdings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,29 @@
end
f866 { 'v.1(2000)- to Date.' }
end

factory :sample_summary_holdings do
f852 do
{ b: 'Library', c: 'Location', h: 'Call Number' }
end

f866 do
{ a: 'the first summary', z: 'extra summary 1' }
end
f866 do
{ a: 'the second summary', z: 'extra summary 2' }
end
f867 do
{ a: 'the first supplement', z: 'extra supplement 1' }
end
f867 do
{ a: 'the second supplement', z: 'extra supplement 2' }
end
f868 do
{ a: 'the first index', z: 'extra index 1' }
end
f868 do
{ a: 'the second index', z: 'extra index 2' }
end
end
end

0 comments on commit 7963d70

Please sign in to comment.