Skip to content

Commit

Permalink
import ndl_bib_id to NdlBibIdRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed May 12, 2020
1 parent 903f76e commit 96dee14
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
10 changes: 4 additions & 6 deletions app/models/concerns/enju_ndl/enju_manifestation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ def self.import_from_ndl_search(options)

def self.import_record(doc)
iss_itemno = URI.parse(doc.at('//dcndl:BibAdminResource[@rdf:about]').values.first).path.split('/').last
identifier_type = IdentifierType.find_or_create_by!(name: 'iss_itemno')
identifier = Identifier.find_by(body: iss_itemno, identifier_type_id: identifier_type.id)
return identifier.manifestation if identifier
ndl_bib_id = NdlBibIdRecord.find_by(body: iss_itemno.split('-')[1].gsub(/^I/, ''))
return ndl_bib_id.manifestation if ndl_bib_id

jpno = doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/JPNO"]').try(:content)

Expand Down Expand Up @@ -164,9 +163,8 @@ def self.import_record(doc)
manifestation: manifestation
)
end
if iss_itemno
identifier[:iss_itemno] = Identifier.new(body: iss_itemno)
identifier[:iss_itemno].identifier_type = IdentifierType.where(name: 'iss_itemno').first || IdentifierType.create!(name: 'iss_itemno')
if iss_itemno.present?
manifestation.ndl_bib_id_record = NdlBibIdRecord.find_or_create_by(body: iss_itemno.split('-')[1].gsub(/^I/, ''))
end
if jpno.present?
manifestation.jpno_record = JpnoRecord.find_or_create_by(body: jpno.strip)
Expand Down
8 changes: 4 additions & 4 deletions spec/models/manifestation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

it "should import a bibliographic record", vcr: true do
manifestation = Manifestation.import_from_ndl_search(isbn: '406258087X')
manifestation.should be_valid
expect(manifestation).to be_valid
end

it "should import isbn", vcr: true do
Manifestation.import_isbn('4797327030').should be_valid
expect(Manifestation.import_isbn('4797327030')).to be_valid
end

it "should import series statement", vcr: true do
manifestation = Manifestation.import_isbn('4106101491')
manifestation.series_statements.count.should eq 1
manifestation.series_statements.first.original_title.should eq '新潮新書'
expect(manifestation.series_statements.count).to eq 1
expect(manifestation.series_statements.first.original_title).to eq '新潮新書'
end

it "should import with ndl_bib_id", vcr: true do
Expand Down
14 changes: 7 additions & 7 deletions spec/models/ndl_book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
context "import" do
it "should import bibliographic record", vcr: true do
manifestation = NdlBook.import_from_sru_response('R100000002-I000010980901-00')
manifestation.manifestation_identifier.should eq 'http://iss.ndl.go.jp/books/R100000002-I000010980901-00'
expect(manifestation.manifestation_identifier).to eq 'http://iss.ndl.go.jp/books/R100000002-I000010980901-00'
expect(manifestation.isbn_records.pluck(:body)).to eq ['9784839931995']
manifestation.classifications.pluck(:category).should eq ["007.64"]
manifestation.identifier_contents(:iss_itemno).should eq ["R100000002-I000010980901-00"]
expect(manifestation.classifications.pluck(:category)).to eq ["007.64"]
expect(manifestation.ndl_bib_id_record.body).to eq "000010980901"
expect(manifestation.jpno_record.body).to eq "21816393"
manifestation.language.name.should eq "Japanese"
expect(manifestation.language.name).to eq "Japanese"
manifestation.creators.first.full_name.should eq '秋葉, 拓哉'
manifestation.creators.first.full_name_transcription.should eq 'アキバ, タクヤ'
manifestation.creators.first.agent_identifier.should eq 'http://id.ndl.go.jp/auth/entity/01208840'
Expand Down Expand Up @@ -188,13 +188,13 @@

it "should import edition", vcr: true do
manifestation = NdlBook.import_from_sru_response("R100000002-I025107686-00")
manifestation.edition_string.should eq "改訂第2版"
expect(manifestation.edition_string).to eq "改訂第2版"
end

it "should import volume title", vcr: true do
manifestation = NdlBook.import_from_sru_response("R100000002-I000011225479-00")
manifestation.original_title.should eq "じゃらん 関東・東北"
manifestation.title_transcription.should eq "ジャラン カントウ トウホク"
expect(manifestation.original_title).to eq "じゃらん 関東・東北"
expect(manifestation.title_transcription).to eq "ジャラン カントウ トウホク"
end

it "should import even with invalid url", vcr: true do
Expand Down

0 comments on commit 96dee14

Please sign in to comment.