Skip to content

Commit

Permalink
added library_stdnums to handle normalizing the LCCN
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Jul 17, 2024
1 parent 932cdb1 commit 4b4828b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -171,6 +172,7 @@ DEPENDENCIES
ffi-icu
httpx
jdbc-sqlite3 (~> 3.28)
library_stdnums
marc
milemarker (~> 1.0)
mysql2
Expand Down
3 changes: 2 additions & 1 deletion lib/authority_browse/remediated_subjects.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "library_stdnums"
module AuthorityBrowse
class RemediatedSubjects
include Enumerable
Expand All @@ -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

Expand Down
15 changes: 12 additions & 3 deletions spec/authority_browse/remediated_subjects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4b4828b

Please sign in to comment.