Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illustrative content #168

Merged
merged 8 commits into from
Dec 9, 2021
2 changes: 2 additions & 0 deletions lib/rdf2marc/model2marc/control_field_008.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def value
field_value[6..14] = '|||||||||'
end
field_value[15..17] = model.place
# Book Illustrative Context
field_value[18] = 'a' if model.book_illustrative_content.present?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ticket said to default this to 'a'

# Language
field_value[35..37] = model.language[0..2] if model.language
# Modified record
Expand Down
1 change: 1 addition & 0 deletions lib/rdf2marc/model2marc/field_300.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(marc_record, model)

def build
append_repeatable('a', model.extents)
append('b', model.other_physical_details)
append_repeatable('c', model.dimensions)
append('3', model.materials_specified)
end
Expand Down
1 change: 1 addition & 0 deletions lib/rdf2marc/models/control_field/general_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class GeneralInfo < Struct
attribute? :date1, Types::String
attribute? :place, Types::String.default('xx').constrained(min_size: 2, max_size: 3)
attribute? :language, Types::String
attribute? :book_illustrative_content, Types::String
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module PhysicalDescriptionField
# Model for 300 - Physical Description.
class PhysicalDescription < Struct
attribute? :extents, Types::Array.of(Types::String)
attribute? :other_physical_details, Types::String
attribute? :dimensions, Types::Array.of(Types::String)
attribute? :materials_specified, Types::String
end
Expand Down
11 changes: 10 additions & 1 deletion lib/rdf2marc/rdf2model/mappers/control_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def generate
place: place,
date_entered: date_entered,
date1: item.instance.query.path_first_literal([[BF.provisionActivity, BF.Publication], [BF.date]]),
language: language
language: language,
book_illustrative_content: book_illustrative_content
}
}
end
Expand Down Expand Up @@ -51,6 +52,14 @@ def language

language_uri.sub(%r{^https?://id.loc.gov/vocabulary/languages/}, '')
end

def book_illustrative_content
illustrative_content_uri = item.instance.query.path_first_uri([BF.illustrativeContent]) ||
item.work.query.path_first_uri([BF.illustrativeContent])
return nil if illustrative_content_uri.blank?

LiteralOrRemoteResolver.resolve_label(term: illustrative_content_uri, item: item)
end
end
end
end
Expand Down
23 changes: 15 additions & 8 deletions lib/rdf2marc/rdf2model/mappers/physical_description_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ def generate

def physical_descriptions
extent_terms = item.instance.query.path_all([[BF.extent, BF.Extent]])
extent_physical_description = extent_terms.sort.map do |extent_term|

# can have multiple illustrativeContent, but only using one
illustrative_content_uri = item.instance.query.path_first_uri([BF.illustrativeContent]) ||
item.work.query.path_first_uri([BF.illustrativeContent])
if illustrative_content_uri
other_physical_details = LiteralOrRemoteResolver.resolve_label(term: illustrative_content_uri, item: item)
end
extent_physical_descriptions = extent_terms.sort.map do |extent_term|
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor: ...descriptionSSSSS

{
extents: item.instance.query.path_all_literal([RDF::RDFS.label], subject_term: extent_term).sort,
# Can be multiple notes, but only using one.
materials_specified: item.instance.query.path_first_literal([[BF.note, BF.Note],
RDF::RDFS.label], subject_term: extent_term)
RDF::RDFS.label], subject_term: extent_term),
other_physical_details: other_physical_details
}
end
dimensions = {
dimensions: item.instance.query.path_all_literal([BF.dimensions]).sort
}
if extent_physical_description.length == 1 && dimensions[:dimensions].length == 1
return [extent_physical_description.first.merge(dimensions)]
dimensions = item.instance.query.path_all_literal([BF.dimensions]).sort
if extent_physical_descriptions.length == 1 && dimensions.length == 1
return [extent_physical_descriptions.first.merge(dimensions: dimensions)]
end

extent_physical_description + [dimensions]
extent_physical_descriptions << { dimensions: dimensions } if dimensions.present?
extent_physical_descriptions
Comment on lines +37 to +43
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor: :dimensions is an attribute of PhysicalDescription class; the existing code was confusing to follow. Tests for more cases around multiple dimensions and multiple physical_decriptions were also added.

end

def media_types
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions spec/rdf2marc/model2marc/control_field_008_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,28 @@

include_examples 'fields', '008'
end

context 'with model with illustrative_content' do
let(:model) do
{
control_fields: {
general_info: {
date_entered: Date.new(2020, 10, 15),
date1: '202x',
place: 'gau',
language: 'ace',
book_illustrative_content: 'Illustrations'
}
}
}
end

let(:expected_fields) { ['008 201015s202u gaua ace||'] }

before do
allow(Date).to receive(:today).and_return(Date.new(2020, 10, 1))
end

include_examples 'fields', '008'
end
end
Loading