enju_ndl 0.0.27 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ class CreateImportRequests < ActiveRecord::Migration
2
+ def change
3
+ create_table :import_requests do |t|
4
+ t.string :isbn
5
+ t.string :state
6
+ t.integer :manifestation_id
7
+ t.integer :user_id
8
+
9
+ t.timestamps
10
+ end
11
+ add_index :import_requests, :isbn
12
+ add_index :import_requests, :manifestation_id
13
+ add_index :import_requests, :user_id
14
+ end
15
+ end
data/lib/enju_ndl.rb CHANGED
@@ -3,6 +3,8 @@ require "enju_ndl/engine"
3
3
  require 'open-uri'
4
4
  require 'enju_ndl/ndl_search'
5
5
  require 'enju_ndl/crd'
6
+ require 'lisbn'
7
+ require 'library_stdnums'
6
8
 
7
9
  module EnjuNdl
8
10
  module ActsAsMethods
@@ -7,13 +7,13 @@ module EnjuNdl
7
7
 
8
8
  module ClassMethods
9
9
  def import_isbn(isbn)
10
- isbn = ISBN_Tools.cleanup(isbn)
11
- raise EnjuNdl::InvalidIsbn unless ISBN_Tools.is_valid?(isbn)
10
+ lisbn = Lisbn.new(isbn)
11
+ raise EnjuNdl::InvalidIsbn unless lisbn.valid?
12
12
 
13
- manifestation = Manifestation.find_by_isbn(isbn)
13
+ manifestation = Manifestation.find_by_isbn(lisbn.isbn)
14
14
  return manifestation if manifestation
15
15
 
16
- doc = return_xml(isbn)
16
+ doc = return_xml(lisbn.isbn)
17
17
  raise EnjuNdl::RecordNotFound unless doc
18
18
  #raise EnjuNdl::RecordNotFound if doc.at('//openSearch:totalResults').content.to_i == 0
19
19
  import_record(doc)
@@ -50,8 +50,8 @@ module EnjuNdl
50
50
  language_id = 1
51
51
  end
52
52
 
53
- isbn = ISBN_Tools.cleanup(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISBN"]').try(:content))
54
- issn_l = ISBN_Tools.cleanup(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISSNL"]').try(:content))
53
+ isbn = Lisbn.new(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISBN"]').try(:content).to_s).try(:isbn)
54
+ issn_l = StdNum::ISSN.normalize(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISSNL"]').try(:content))
55
55
  classification_urls = doc.xpath('//dcterms:subject[@rdf:resource]').map{|subject| subject.attributes['resource'].value}
56
56
  if classification_urls
57
57
  ndc9_url = classification_urls.map{|url| URI.parse(URI.escape(url))}.select{|u| u.path.split('/').reverse[1] == 'ndc9'}.first
@@ -172,9 +172,9 @@ module EnjuNdl
172
172
 
173
173
  def normalize_isbn(isbn)
174
174
  if isbn.length == 10
175
- ISBN_Tools.isbn10_to_isbn13(isbn)
175
+ Lisbn.new(isbn).isbn13
176
176
  else
177
- ISBN_Tools.isbn13_to_isbn10(isbn)
177
+ Lisbn.new(isbn).isbn10
178
178
  end
179
179
  end
180
180
 
@@ -1,3 +1,3 @@
1
1
  module EnjuNdl
2
- VERSION = "0.0.27"
2
+ VERSION = "0.0.29"
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.27
4
+ version: 0.0.29
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-30 00:00:00.000000000 Z
12
+ date: 2012-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -155,6 +155,38 @@ dependencies:
155
155
  - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: lisbn
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: library_stdnums
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :runtime
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
158
190
  - !ruby/object:Gem::Dependency
159
191
  name: sqlite3
160
192
  requirement: !ruby/object:Gem::Requirement
@@ -250,6 +282,7 @@ files:
250
282
  - config/locales/en.yml
251
283
  - config/locales/ja.yml
252
284
  - config/routes.rb
285
+ - db/migrate/20100129142347_create_import_requests.rb
253
286
  - lib/enju_ndl/crd.rb
254
287
  - lib/enju_ndl/engine.rb
255
288
  - lib/enju_ndl/ndl_search.rb