diff --git a/marc_to_solr/lib/format/bib_format.rb b/marc_to_solr/lib/format/bib_format.rb index 7918af75..8f443caf 100644 --- a/marc_to_solr/lib/format/bib_format.rb +++ b/marc_to_solr/lib/format/bib_format.rb @@ -12,8 +12,10 @@ def initialize(record) ldr = record.leader type = ldr[6] lev = ldr[7] + check_pulfa = record['035'] && record['035']['a'].start_with?('(PULFA)') + check_dacs = record['040'] && record['040']['e'] == 'dacs' @code = [] - @code << self.determine_bib_code(type, lev) + @code << self.determine_bib_code(type, lev, check_pulfa, check_dacs) @code << 'WM' if microform? record @code = @code.flatten # Removed per @tampakis recommendation to keep items with an unknown format @@ -21,7 +23,7 @@ def initialize(record) # @code << 'XX' if @code.empty? end - def determine_bib_code(type, lev) + def determine_bib_code(type, lev, check_pulfa, check_dacs) format = [] format << "AJ" if bibformat_jn(type, lev) # journal format << "CF" if bibformat_cf(type, lev) # data file @@ -31,13 +33,14 @@ def determine_bib_code(type, lev) format << "AU" if bibformat_au(type, lev) # audio format << "MP" if bibformat_mp(type, lev) # map format << "MW" if bibformat_mw(type, lev) # manuscript - format << "BK" if bibformat_bk(type, lev) # book + format << "BK" if bibformat_bk(type, lev, check_pulfa) # book format << "DB" if bibformat_db(type, lev) # databases + format << "XA" if bibformat_xa(type, lev, check_pulfa, check_dacs) # archival item format end - def bibformat_bk(type, lev) - (type == 't') || ((type == 'a') && %w[a b c d m].include?(lev)) + def bibformat_bk(type, lev, check_pulfa) + ((type == 't') && !check_pulfa) || ((type == 'a') && %w[a b c d m].include?(lev)) end def bibformat_db(type, lev) @@ -76,6 +79,10 @@ def bibformat_mw(type, _lev) %w[d f p t].include?(type) end + def bibformat_xa(type, lev, check_pulfa, check_dacs) + (type == 't') && (lev == 'm') && check_pulfa && check_dacs + end + private def microform?(record) diff --git a/marc_to_solr/translation_maps/format.rb b/marc_to_solr/translation_maps/format.rb index b6aa4fad..e73e41c0 100644 --- a/marc_to_solr/translation_maps/format.rb +++ b/marc_to_solr/translation_maps/format.rb @@ -35,6 +35,7 @@ "VL" => "Motion picture", "VM" => "Visual material", "VP" => "Video/Projected medium", + "XA" => "Archival Item", "WM" => "Microform", "XC" => "Conference", "XS" => "Statistics", diff --git a/spec/marc_to_solr/lib/format_spec.rb b/spec/marc_to_solr/lib/format_spec.rb index 3f2a3799..6f29d9ea 100644 --- a/spec/marc_to_solr/lib/format_spec.rb +++ b/spec/marc_to_solr/lib/format_spec.rb @@ -13,10 +13,39 @@ 'Musical score' => ['c ', 'd '], 'Audio' => ['i ', 'j '], 'Map' => ['e '], - 'Manuscript' => ['d ', 'f ', 't ', 'p '] - # 'Unknown' => [' ', 'zz'] + 'Manuscript' => ['d ', 'f ', 't ', 'p '], + 'Archival Item' => ['tm'] }.each do |k, v| it "properly determines format for #{k}" do + v.each do |c| + marc.leader[6..7] = c + + if marc.leader[6] == 'a' + field = MARC::DataField.new('035','0','0', + MARC::Subfield.new('a', '(PULFA)')) + marc.append(field) + end + + if c == 'tm' + field = MARC::DataField.new('035','0','0', + MARC::Subfield.new('a', '(PULFA)')) + marc.append(field) + field = MARC::DataField.new('040','0','0', + MARC::Subfield.new('e', 'dacs')) + marc.append(field) + end + fmt = Format.new(marc).bib_format + expect(Traject::TranslationMap.new("format").translate_array!(fmt)).to include k + end + end + end + +let(:marc) { MARC::Record.new } + + { + 'Book' => ['tm'] + }.each do |k, v| + it "properly determines format for 'tm' when the record is non-PULFA" do v.each do |c| marc.leader[6..7] = c fmt = Format.new(marc).bib_format