Skip to content

Commit

Permalink
Merge pull request #167 from LD4P/table-of-contents
Browse files Browse the repository at this point in the history
Map tableOfContents to 505 field
  • Loading branch information
justinlittman authored Dec 9, 2021
2 parents 997881f + 74f93b0 commit 67fedf9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
17 changes: 17 additions & 0 deletions lib/rdf2marc/model2marc/field_505.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Rdf2marc
module Model2marc
# Maps model to field 505
class Field505 < Field
def initialize(marc_record, value)
super(marc_record, value, '505')
end

def build
field.indicator1 = '0'
append('a', model)
end
end
end
end
2 changes: 2 additions & 0 deletions lib/rdf2marc/model2marc/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def marc_record
add_repeating_field(Field338, record_model.physical_description_fields.carrier_types, marc_record)
add_repeating_field(Field490, record_model.series_statement_fields.series_statements, marc_record)
add_repeating_field(Field500, record_model.note_fields.general_notes, marc_record)
add_repeating_field(Field505, record_model.note_fields.table_of_contents, marc_record)

add_repeating_field(Field600, record_model.subject_access_fields.personal_names, marc_record)
add_repeating_field(Field610, record_model.subject_access_fields.corporate_names, marc_record)
add_repeating_field(Field611, record_model.subject_access_fields.meeting_names, marc_record)
Expand Down
1 change: 1 addition & 0 deletions lib/rdf2marc/models/note_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Models
# Model for 5XX: Note Fields.
class NoteFields < Struct
attribute? :general_notes, Types::Array.of(NoteField::GeneralNote)
attribute? :table_of_contents, Types::Array.of(Types::String)
end
end
end
7 changes: 6 additions & 1 deletion lib/rdf2marc/rdf2model/mappers/note_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ def generate
notes = general_notes
notes << provision_activity_statement if provision_activity_statement
{
general_notes: notes
general_notes: notes,
table_of_contents: table_of_contents
}
end

private

def table_of_contents
item.work.query.path_all_literal([[BF.tableOfContents, BF.TableOfContents], RDF::RDFS.label])
end

def general_notes
notes = item.instance.query.path_all_literal([[BF.note, BF.Note], RDF::RDFS.label]) +
item.work.query.path_all_literal([[BF.note, BF.Note], RDF::RDFS.label])
Expand Down
22 changes: 22 additions & 0 deletions spec/rdf2marc/model2marc/field_505_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

RSpec.describe Rdf2marc::Model2marc::Field505 do
let(:model) do
{
note_fields: {
table_of_contents: %w[
one two
]
}
}
end

let(:expected_fields) do
[
'505 0 $a one',
'505 0 $a two'
]
end

include_examples 'fields', '505'
end
11 changes: 9 additions & 2 deletions spec/rdf2marc/rdf2model/mappers/note_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@
describe 'general notes' do
let(:ttl) do
<<~TTL
<#{work_term}> <http://id.loc.gov/ontologies/bibframe/note> _:b1.
<#{work_term}> <http://id.loc.gov/ontologies/bibframe/note> _:b1;
<http://id.loc.gov/ontologies/bibframe/tableOfContents> _:b3.
_:b1 a <http://id.loc.gov/ontologies/bibframe/Note>;
<http://www.w3.org/2000/01/rdf-schema#label> "Recast in bronze from artist's plaster original of 1903."@eng.
<#{instance_term}> <http://id.loc.gov/ontologies/bibframe/note> _:b2;
<http://id.loc.gov/ontologies/bibframe/provisionActivityStatement> "provision activity statement!"@eng.
_:b2 a <http://id.loc.gov/ontologies/bibframe/Note>;
<http://www.w3.org/2000/01/rdf-schema#label> "Translated from German."@eng.
_:b3 a <http://id.loc.gov/ontologies/bibframe/TableOfContents>;
<http://www.w3.org/2000/01/rdf-schema#label> "Introduction : the philosopher's stone -- The field atlas :maps and meaning across California's forests"@eng.
TTL
end
let(:toc) do
"Introduction : the philosopher's stone -- The field atlas :maps and meaning across California's forests"
end

let(:model) do
{
Expand All @@ -38,7 +44,8 @@
{
general_note: 'Transcribed publication statement: provision activity statement!'
}
]
],
table_of_contents: [toc]
}
end

Expand Down

0 comments on commit 67fedf9

Please sign in to comment.