From 74f93b077ad0f429e02514efa5567fa70faba773 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 8 Dec 2021 14:34:29 -0600 Subject: [PATCH] Map tableOfContents to 505 field --- lib/rdf2marc/model2marc/field_505.rb | 17 ++++++++++++++ lib/rdf2marc/model2marc/record.rb | 2 ++ lib/rdf2marc/models/note_fields.rb | 1 + lib/rdf2marc/rdf2model/mappers/note_fields.rb | 7 +++++- spec/rdf2marc/model2marc/field_505_spec.rb | 22 +++++++++++++++++++ .../rdf2model/mappers/note_fields_spec.rb | 11 ++++++++-- 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 lib/rdf2marc/model2marc/field_505.rb create mode 100644 spec/rdf2marc/model2marc/field_505_spec.rb diff --git a/lib/rdf2marc/model2marc/field_505.rb b/lib/rdf2marc/model2marc/field_505.rb new file mode 100644 index 0000000..9a327ac --- /dev/null +++ b/lib/rdf2marc/model2marc/field_505.rb @@ -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 diff --git a/lib/rdf2marc/model2marc/record.rb b/lib/rdf2marc/model2marc/record.rb index 1966a52..3991037 100644 --- a/lib/rdf2marc/model2marc/record.rb +++ b/lib/rdf2marc/model2marc/record.rb @@ -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) diff --git a/lib/rdf2marc/models/note_fields.rb b/lib/rdf2marc/models/note_fields.rb index c853dc3..4111a25 100644 --- a/lib/rdf2marc/models/note_fields.rb +++ b/lib/rdf2marc/models/note_fields.rb @@ -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 diff --git a/lib/rdf2marc/rdf2model/mappers/note_fields.rb b/lib/rdf2marc/rdf2model/mappers/note_fields.rb index 08b080e..16ecd64 100644 --- a/lib/rdf2marc/rdf2model/mappers/note_fields.rb +++ b/lib/rdf2marc/rdf2model/mappers/note_fields.rb @@ -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]) diff --git a/spec/rdf2marc/model2marc/field_505_spec.rb b/spec/rdf2marc/model2marc/field_505_spec.rb new file mode 100644 index 0000000..2632c81 --- /dev/null +++ b/spec/rdf2marc/model2marc/field_505_spec.rb @@ -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 diff --git a/spec/rdf2marc/rdf2model/mappers/note_fields_spec.rb b/spec/rdf2marc/rdf2model/mappers/note_fields_spec.rb index fc9137d..08ff7c9 100644 --- a/spec/rdf2marc/rdf2model/mappers/note_fields_spec.rb +++ b/spec/rdf2marc/rdf2model/mappers/note_fields_spec.rb @@ -16,15 +16,21 @@ describe 'general notes' do let(:ttl) do <<~TTL - <#{work_term}> _:b1. + <#{work_term}> _:b1; + _:b3. _:b1 a ; "Recast in bronze from artist's plaster original of 1903."@eng. <#{instance_term}> _:b2; "provision activity statement!"@eng. _:b2 a ; "Translated from German."@eng. + _:b3 a ; + "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 { @@ -38,7 +44,8 @@ { general_note: 'Transcribed publication statement: provision activity statement!' } - ] + ], + table_of_contents: [toc] } end