From 4b4828bcdf588c4d0fa7e6bacc19b40ec7ff0fbb Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Wed, 17 Jul 2024 11:37:57 -0400 Subject: [PATCH] added library_stdnums to handle normalizing the LCCN --- Gemfile | 1 + Gemfile.lock | 2 ++ lib/authority_browse/remediated_subjects.rb | 3 ++- spec/authority_browse/remediated_subjects_spec.rb | 15 ++++++++++++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 6b125e01..5aa46a44 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem "thor" gem "marc" gem "solr_cloud-connection", ">= 0.4.0" gem "alma_rest_client", github: "mlibrary/alma_rest_client", tag: "v2.0.0" +gem "library_stdnums" gem "sqlite3", "~> 1.4", platforms: :mri gem "jdbc-sqlite3", "~> 3.28", platforms: :jruby diff --git a/Gemfile.lock b/Gemfile.lock index b5ba291f..a2822388 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,6 +59,7 @@ GEM concurrent-ruby (~> 1.0) json (2.7.1) language_server-protocol (3.17.0.3) + library_stdnums (1.6.0) lint_roller (1.1.0) marc (1.2.0) rexml @@ -171,6 +172,7 @@ DEPENDENCIES ffi-icu httpx jdbc-sqlite3 (~> 3.28) + library_stdnums marc milemarker (~> 1.0) mysql2 diff --git a/lib/authority_browse/remediated_subjects.rb b/lib/authority_browse/remediated_subjects.rb index 377cfde5..5998204d 100644 --- a/lib/authority_browse/remediated_subjects.rb +++ b/lib/authority_browse/remediated_subjects.rb @@ -1,3 +1,4 @@ +require "library_stdnums" module AuthorityBrowse class RemediatedSubjects include Enumerable @@ -23,7 +24,7 @@ def id end def loc_id - loc_id_str = @record["010"]["a"].gsub(/\s/, "") + loc_id_str = StdNum::LCCN.normalize(@record["010"]["a"]) "http://id.loc.gov/authorities/subjects/#{loc_id_str}" end diff --git a/spec/authority_browse/remediated_subjects_spec.rb b/spec/authority_browse/remediated_subjects_spec.rb index 37ddf45b..0ae391f4 100644 --- a/spec/authority_browse/remediated_subjects_spec.rb +++ b/spec/authority_browse/remediated_subjects_spec.rb @@ -13,15 +13,24 @@ end RSpec.describe AuthorityBrowse::RemediatedSubjects::Entry do + before(:each) do + @subject_record = fixture("remediated_subject.xml") + end subject do - described_class.new(fixture("remediated_subject.xml")) + described_class.new(@subject_record) end it "returns the mms_id for the #id" do expect(subject.id).to eq("98187481368506381") end - it "returns the url for the #loc_id (minus the extension) from 010$a" do - expect(subject.loc_id).to eq("http://id.loc.gov/authorities/subjects/sh2008104250") + context "#loc_id" do + it "returns the url for the #loc_id (minus the extension) from 010$a" do + expect(subject.loc_id).to eq("http://id.loc.gov/authorities/subjects/sh2008104250") + end + it "handles invalid loc_id by returning a url with an empty string" do + @subject_record.gsub!("sh2008104250", ";;;;;") + expect(subject.loc_id).to eq("http://id.loc.gov/authorities/subjects/") + end end it "returns the #label from 150$a" do