enju_ndl 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,7 @@ class NdlBook
21
21
  end
22
22
 
23
23
  def self.find_by_isbn(isbn)
24
- url = "http://api.porta.ndl.go.jp/servicedp/opensearch?dpid=zomoku&isbn=#{isbn}&cnt=1&idx=1"
24
+ url = "http://iss.ndl.go.jp/api/opensearch?dpid=iss-ndl-opac&isbn=#{isbn}&cnt=1&idx=1"
25
25
  Rails.logger.debug url
26
26
  xml = open(url).read
27
27
  doc = Nokogiri::XML(xml).at('//channel/item')
@@ -36,47 +36,11 @@ class NdlBook
36
36
  def self.import_from_sru_response(jpno)
37
37
  manifestation = Manifestation.where(:nbn => jpno).first
38
38
  return if manifestation
39
- response = Nokogiri::XML(open("http://api.porta.ndl.go.jp/servicedp/SRUDp?operation=searchRetrive&maximumRecords=10&recordSchema=dcndl_porta&query=%28jpno=#{jpno}%29")).at('//xmlns:recordData', 'xmlns' => "http://www.loc.gov/zing/srw/")
39
+ url = "http://iss.ndl.go.jp/api/sru?operation=searchRetrieve&recordSchema=dcndl&&maximumRecords=1&&query=%28jpno=#{jpno}%29"
40
+ response = Nokogiri::XML(open("http://iss.ndl.go.jp/api/sru?operation=searchRetrieve&recordSchema=dcndl&&maximumRecords=1&&query=%28jpno=#{jpno}%29")).at('//xmlns:recordData')
40
41
  return unless response.content
41
42
  doc = Nokogiri::XML(response.content)
42
- title = {
43
- :manifestation => doc.xpath('//dc:title').collect(&:content).join(' ').tr('a-zA-Z0-9 ', 'a-zA-Z0-9 ').squeeze(' '),
44
- :transcription => doc.xpath('//dcndl:titleTranscription').collect(&:content).join(' ').tr('a-zA-Z0-9 ', 'a-zA-Z0-9 ').squeeze(' '),
45
- :original => doc.xpath('//dcterms:alternative').collect(&:content).join(' ').tr('a-zA-Z0-9 ', 'a-zA-Z0-9 ').squeeze(' ')
46
- }
47
- lang = doc.at('//dc:language[@xsi:type="dcterms:ISO639-2"]').try(:content)
48
- creators = []
49
- doc.xpath('//dc:creator[@xsi:type="dcndl:NDLNH"]').each do |creator|
50
- creators << creator.content.tr('a-zA-Z0-9 ‖', 'a-zA-Z0-9 ')
51
- end
52
- publishers = []
53
- doc.xpath('//dc:publisher').each do |publisher|
54
- publishers << publisher.content.tr('a-zA-Z0-9 ‖', 'a-zA-Z0-9 ')
55
- end
56
- pub_date = doc.at('//dcterms:issued').content.try(:tr, '0-9.', '0-9-').to_s.gsub(/(.*)/, '')
57
- unless pub_date =~ /^\d+(-\d{0,2}){0,2}$/
58
- pub_date = nil
59
- end
60
-
61
- Manifestation.transaction do
62
- language = Language.where(:iso_639_2 => lang.downcase).first if lang
63
- manifestation = Manifestation.new(
64
- :original_title => title[:manifestation],
65
- :title_transcription => title[:title_transcription],
66
- :title_alternative => title[:original],
67
- :pub_date => pub_date,
68
- :isbn => doc.at('//dc:identifier[@xsi:type="dcndl:ISBN"]').try(:content),
69
- :nbn => doc.at('//dc:identifier[@xsi:type="dcndl:JPNO"]').content,
70
- :ndc => doc.at('//dc:subject[@xsi:type="dcndl:NDC"]').try(:content).try(:tr, '0-9.', '0-9.').to_s.gsub(/(.*)/, '')
71
- )
72
- manifestation.language = language if language
73
- patron_creators = Patron.import_patrons(creators.zip([]).map{|f,t| {:full_name => f, :full_name_transcription => t}}).uniq
74
- patron_publishers = Patron.import_patrons(publishers.zip([]).map{|f,t| {:full_name => f, :full_name_transcription => t}}).uniq
75
- manifestation.creators << patron_creators
76
- manifestation.publishers << patron_publishers
77
- manifestation.save!
78
- end
79
- manifestation
43
+ Manifestation.import_record(doc)
80
44
  end
81
45
 
82
46
  attr_accessor :url
@@ -14,10 +14,13 @@ module EnjuNdl
14
14
  return manifestation if manifestation
15
15
 
16
16
  doc = return_xml(isbn)
17
- #raise EnjuNdl::RecordNotFound if doc.at('//openSearch:totalResults').content.to_i == 0
18
17
  raise EnjuNdl::RecordNotFound unless doc
18
+ #raise EnjuNdl::RecordNotFound if doc.at('//openSearch:totalResults').content.to_i == 0
19
+ import_record(doc)
20
+ end
19
21
 
20
- pub_date, language, nbn = nil, nil, nil
22
+ def import_record(doc)
23
+ pub_date, language, nbn, ndc, isbn = nil, nil, nil, nil, nil
21
24
 
22
25
  publishers = get_publishers(doc).zip([]).map{|f,t| {:full_name => f, :full_name_transcription => t}}
23
26
 
@@ -31,10 +34,18 @@ module EnjuNdl
31
34
  end
32
35
 
33
36
  language = get_language(doc)
37
+ isbn = doc.at('./dc:identifier[@xsi:type="dcndl:ISBN"]').try(:content).to_s
34
38
  nbn = doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/JPNO"]').content
35
39
  classification_urls = doc.xpath('//dcterms:subject[@rdf:resource]').map{|subject| subject.attributes['resource'].value}
36
- ndc = classification_urls.map{|url| URI.parse(url)}.select{|url| url.path.split('/').reverse[1] == 'ndc9'}.first.path.split('/').last
40
+ if classification_urls
41
+ ndc9_url = classification_urls.map{|url| URI.parse(url)}.select{|u| u.path.split('/').reverse[1] == 'ndc9'}.first
42
+ if ndc9_url
43
+ ndc = ndc9_url.path.split('/').last
44
+ end
45
+ end
46
+ description = doc.at('//dcterms:abstract').try(:content)
37
47
 
48
+ manifestation = nil
38
49
  Patron.transaction do
39
50
  publisher_patrons = Patron.import_patrons(publishers)
40
51
  language_id = Language.where(:iso_639_2 => language).first.id rescue 1
@@ -47,15 +58,15 @@ module EnjuNdl
47
58
  :language_id => language_id,
48
59
  :isbn => isbn,
49
60
  :pub_date => pub_date,
61
+ :description => description,
50
62
  :nbn => nbn,
51
63
  :ndc => ndc
52
64
  )
53
- manifestation.ndc = ndc
54
65
  manifestation.publishers << publisher_patrons
66
+ create_frbr_instance(doc, manifestation)
55
67
  end
56
68
 
57
69
  #manifestation.send_later(:create_frbr_instance, doc.to_s)
58
- create_frbr_instance(doc, manifestation)
59
70
  return manifestation
60
71
  end
61
72
 
@@ -1,3 +1,3 @@
1
1
  module EnjuNdl
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enju_ndl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-06 00:00:00.000000000 Z
12
+ date: 2012-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70123411904400 !ruby/object:Gem::Requirement
16
+ requirement: &70273563941240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '3'
21
+ version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70123411904400
24
+ version_requirements: *70273563941240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: devise
27
- requirement: &70123411918620 !ruby/object:Gem::Requirement
27
+ requirement: &70273563940820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70123411918620
35
+ version_requirements: *70273563940820
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &70123411945180 !ruby/object:Gem::Requirement
38
+ requirement: &70273563940360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70123411945180
46
+ version_requirements: *70273563940360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: will_paginate
49
- requirement: &70123411964080 !ruby/object:Gem::Requirement
49
+ requirement: &70273563939860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70123411964080
57
+ version_requirements: *70273563939860
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3
60
- requirement: &70123412083020 !ruby/object:Gem::Requirement
60
+ requirement: &70273563939440 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70123412083020
68
+ version_requirements: *70273563939440
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-rails
71
- requirement: &70123412079920 !ruby/object:Gem::Requirement
71
+ requirement: &70273563938980 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70123412079920
79
+ version_requirements: *70273563938980
80
80
  description: NDL WebAPI wrapper for Next-L Enju
81
81
  email:
82
82
  - tanabe@mwr.mediacom.keio.ac.jp