enju_ndl 0.3.2 → 0.4.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +2 -7
  4. data/Rakefile +24 -13
  5. data/app/models/concerns/enju_ndl/enju_agent.rb +12 -0
  6. data/{lib/enju_ndl/ndl_search.rb → app/models/concerns/enju_ndl/enju_manifestation.rb} +36 -30
  7. data/{lib/enju_ndl/crd.rb → app/models/concerns/enju_ndl/enju_question.rb} +12 -9
  8. data/app/models/jpno_record.rb +14 -0
  9. data/app/models/ndl_bib_id_record.rb +14 -0
  10. data/app/models/ndla_record.rb +14 -0
  11. data/db/migrate/20170116150432_create_jpno_records.rb +10 -0
  12. data/db/migrate/20171126072934_create_ndla_records.rb +10 -0
  13. data/db/migrate/20190501043418_create_ndl_bib_id_records.rb +10 -0
  14. data/lib/enju_ndl.rb +1 -21
  15. data/lib/enju_ndl/version.rb +1 -1
  16. data/spec/dummy/app/models/user.rb +5 -1
  17. data/spec/dummy/bin/bundle +1 -1
  18. data/spec/dummy/bin/setup +1 -3
  19. data/spec/dummy/bin/update +4 -2
  20. data/spec/dummy/bin/yarn +3 -3
  21. data/spec/dummy/config/application.rb +2 -1
  22. data/spec/dummy/config/database.yml +70 -9
  23. data/spec/dummy/config/initializers/assets.rb +1 -1
  24. data/spec/dummy/config/initializers/session_store.rb +8 -0
  25. data/spec/dummy/db/migrate/20100606065209_create_user_has_roles.rb +2 -4
  26. data/spec/dummy/db/migrate/20140122054321_create_profiles.rb +4 -5
  27. data/spec/dummy/db/migrate/20190630113817_add_display_name_translations_to_library_group.rb +12 -0
  28. data/spec/dummy/db/migrate/20190630115523_add_login_banner_translations_to_library_group.rb +6 -0
  29. data/spec/dummy/db/migrate/20190630151446_add_display_name_translations_to_role.rb +5 -0
  30. data/spec/dummy/db/migrate/20190712163038_add_display_name_translations_to_carrier_type.rb +21 -0
  31. data/spec/dummy/db/migrate/20190713114940_add_profile_id_to_user.rb +5 -0
  32. data/spec/dummy/db/migrate/20190713115451_add_full_name_translations_to_profile.rb +5 -0
  33. data/spec/dummy/db/schema.rb +195 -147
  34. data/spec/dummy/db/test.sqlite3 +0 -0
  35. data/spec/fixtures/agent_types.yml +10 -11
  36. data/spec/fixtures/carrier_types.yml +28 -24
  37. data/spec/fixtures/frequencies.yml +17 -25
  38. data/spec/fixtures/profiles.yml +9 -12
  39. data/spec/fixtures/roles.yml +16 -13
  40. data/spec/fixtures/users.yml +7 -0
  41. data/spec/rails_helper.rb +5 -1
  42. metadata +377 -445
  43. data/app/assets/config/enju_ndl_manifest.js +0 -0
  44. data/spec/dummy/db/migrate/20190818075603_add_memo_to_manifestation.rb +0 -5
  45. data/spec/dummy/db/migrate/20190818075628_add_memo_to_item.rb +0 -5
  46. data/spec/dummy/db/migrate/20191219122214_create_custom_properties.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92421cf0fd4020c70ee6df9208a7482a61ef48c008bde86740f7fa72ccf93d06
4
- data.tar.gz: f5ab238011643159d888db5ef2c83bf887d5c58170186d58633ad26bd4be3500
3
+ metadata.gz: 4d0f49eaefad35b92b61f8faea93f689ec9d62868edf983f4a95ebc3c9a58e57
4
+ data.tar.gz: 76890bbede710e50747b69687b5bdfaa67856a1e7ad7aafe80faf8a67e38b9e9
5
5
  SHA512:
6
- metadata.gz: c3d6cf745d70ee6849efac32ac30eef13de9f5bd1aaa70071d32f0846c069a14b04dde15c83cfb7fe0518ec597221f6d085eaeca203387fd8a4ad12365f9756d
7
- data.tar.gz: ca857f98309d0e2bbab305083a2be5c7814fa12e54157cb44a613707c06bea72cff23b110600c777a6d5d4cde91dc70e801a654fa9b5c3a9421da6d354c6a1cb
6
+ metadata.gz: 45050db6983fc8e30525fe1006170f43da82a6aae370bd4194461eb7a7f80523827f8426a876803ba8ba300f25d775e6d3690b6adeefde45d85793e1e6742e9d
7
+ data.tar.gz: b105f3c85470fb0cc08c1396906cff0d1d6a397741a95441d0b368fb8c231ace97e678193619917e403cc8e5adf241c6cb07b925cde1fe8e9f2d6b9328bd9dd6
@@ -1,4 +1,4 @@
1
- Copyright 2015 Project Next-L
1
+ Copyright 2012 Kosuke Tanabe
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,11 +1,6 @@
1
1
  # EnjuNdl
2
- [<img src="https://travis-ci.com/next-l/enju_ndl.svg?branch=1.3" alt="Build
3
- Status" />](https://travis-ci.com/next-l/enju_ndl) [<img
4
- src="https://coveralls.io/repos/next-l/enju_ndl/badge.svg?branch=1.3&service=g
5
- ithub" alt="Coverage Status"
6
- />](https://coveralls.io/github/next-l/enju_ndl?branch=1.3) [<img
7
- src="https://hakiri.io/github/next-l/enju_ndl/1.3.svg" alt="security"
8
- />](https://hakiri.io/github/next-l/enju_ndl/1.3)
2
+ [![CircleCI](https://circleci.com/gh/next-l/enju_ndl/tree/2.x.svg?style=svg)](https://circleci.com/gh/next-l/enju_ndl/tree/2.x)
3
+ [![Coverage Status](https://coveralls.io/repos/github/next-l/enju_ndl/badge.svg?branch=2.x)](https://coveralls.io/github/next-l/enju_ndl?branch=2.x)
9
4
 
10
5
  This project rocks and uses MIT-LICENSE.
11
6
 
data/Rakefile CHANGED
@@ -1,16 +1,10 @@
1
- #!/usr/bin/env rake
2
1
  begin
3
2
  require 'bundler/setup'
4
3
  rescue LoadError
5
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
5
  end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
6
+
7
+ require 'rdoc/task'
14
8
 
15
9
  RDoc::Task.new(:rdoc) do |rdoc|
16
10
  rdoc.rdoc_dir = 'rdoc'
@@ -23,13 +17,30 @@ end
23
17
  APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
18
  load 'rails/tasks/engine.rake'
25
19
 
26
- Bundler::GemHelper.install_tasks
27
20
 
28
- require 'rspec/core'
29
- require 'rspec/core/rake_task'
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
30
28
 
31
- RSpec::Core::RakeTask.new(:spec) do |spec|
32
- spec.pattern = FileList['spec/**/*_spec.rb']
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ begin
38
+ require 'rspec/core/rake_task'
39
+
40
+ RSpec::Core::RakeTask.new(:spec)
41
+
42
+ rescue LoadError
43
+ # no rspec available
33
44
  end
34
45
 
35
46
  task :default => :spec
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnjuNdl
4
+ module EnjuAgent
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ has_one :ndla_record
9
+ end
10
+ end
11
+ end
12
+
@@ -1,24 +1,31 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module EnjuNdl
3
- module NdlSearch
4
- def self.included(base)
5
- base.extend ClassMethods
6
- end
4
+ module EnjuManifestation
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ has_one :jpno_record
9
+ has_one :ndl_bib_id_record
10
+ searchable do
11
+ string :jpno do
12
+ jpno_record.try(:body)
13
+ end
14
+ end
7
15
 
8
- module ClassMethods
9
- def import_isbn(isbn)
16
+ def self.import_isbn(isbn)
10
17
  manifestation = Manifestation.import_from_ndl_search(isbn: isbn)
11
18
  manifestation
12
19
  end
13
20
 
14
21
  # Use http://www.ndl.go.jp/jp/dlib/standards/opendataset/aboutIDList.txt
15
- def import_ndl_bib_id(ndl_bib_id)
22
+ def self.import_ndl_bib_id(ndl_bib_id)
16
23
  url = "https://iss.ndl.go.jp/books/R100000002-I#{ndl_bib_id}-00.rdf"
17
24
  doc = Nokogiri::XML(Faraday.get(url).body)
18
25
  import_record(doc)
19
26
  end
20
27
 
21
- def import_from_ndl_search(options)
28
+ def self.import_from_ndl_search(options)
22
29
  # if options[:isbn]
23
30
  lisbn = Lisbn.new(options[:isbn])
24
31
  raise EnjuNdl::InvalidIsbn unless lisbn.valid?
@@ -33,11 +40,10 @@ module EnjuNdl
33
40
  import_record(doc)
34
41
  end
35
42
 
36
- def import_record(doc)
43
+ def self.import_record(doc)
37
44
  iss_itemno = URI.parse(doc.at('//dcndl:BibAdminResource[@rdf:about]').values.first).path.split('/').last
38
- identifier_type = IdentifierType.where(name: 'iss_itemno').first
39
- identifier_type ||= IdentifierType.where(name: 'iss_itemno').create!
40
- identifier = Identifier.where(body: iss_itemno, identifier_type_id: identifier_type.id).first
45
+ identifier_type = IdentifierType.where(name: 'iss_itemno').first_or_create!
46
+ identifier = Identifier.find_by(body: iss_itemno, identifier_type_id: identifier_type.id)
41
47
  return identifier.manifestation if identifier
42
48
 
43
49
  jpno = doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/JPNO"]').try(:content)
@@ -59,7 +65,7 @@ module EnjuNdl
59
65
  end
60
66
  end
61
67
 
62
- language = Language.where(iso_639_2: get_language(doc)).first
68
+ language = Language.find_by(iso_639_2: get_language(doc))
63
69
  language_id = if language
64
70
  language.id
65
71
  else
@@ -75,8 +81,8 @@ module EnjuNdl
75
81
  doc.xpath('//dcndl:materialType[@rdf:resource]').each do |d|
76
82
  case d.attributes['resource'].try(:content)
77
83
  when 'http://ndl.go.jp/ndltype/Book'
78
- carrier_type = CarrierType.where(name: 'print').first
79
- content_type = ContentType.where(name: 'text').first
84
+ carrier_type = CarrierType.find_by(name: 'print')
85
+ content_type = ContentType.find_by(name: 'text')
80
86
  when 'http://ndl.go.jp/ndltype/Braille'
81
87
  content_type = ContentType.where(name: 'tactile_text').first
82
88
  # when 'http://ndl.go.jp/ndltype/ComputerProgram'
@@ -194,7 +200,7 @@ module EnjuNdl
194
200
  manifestation
195
201
  end
196
202
 
197
- def create_additional_attributes(doc, manifestation)
203
+ def self.create_additional_attributes(doc, manifestation)
198
204
  title = get_title(doc)
199
205
  creators = get_creators(doc).uniq
200
206
  subjects = get_subjects(doc).uniq
@@ -227,7 +233,7 @@ module EnjuNdl
227
233
  if classification_urls
228
234
  classification_urls.each do |url|
229
235
  begin
230
- ndc_url = URI.parse(url)
236
+ ndc_url = URI.parse(URI.escape(url))
231
237
  rescue URI::InvalidURIError
232
238
  end
233
239
  next unless ndc_url
@@ -251,7 +257,7 @@ module EnjuNdl
251
257
  end
252
258
  end
253
259
 
254
- def search_ndl(query, options = {})
260
+ def self.search_ndl(query, options = {})
255
261
  options = { dpid: 'iss-ndl-opac', item: 'any', idx: 1, per_page: 10, raw: false, mediatype: 1 }.merge(options)
256
262
  doc = nil
257
263
  results = {}
@@ -267,7 +273,7 @@ module EnjuNdl
267
273
  end
268
274
  end
269
275
 
270
- def normalize_isbn(isbn)
276
+ def self.normalize_isbn(isbn)
271
277
  if isbn.length == 10
272
278
  Lisbn.new(isbn).isbn13
273
279
  else
@@ -275,7 +281,7 @@ module EnjuNdl
275
281
  end
276
282
  end
277
283
 
278
- def return_xml(isbn)
284
+ def self.return_xml(isbn)
279
285
  rss = search_ndl(isbn, dpid: 'iss-ndl-opac', item: 'isbn')
280
286
  if rss.channel.totalResults.to_i == 0
281
287
  isbn = normalize_isbn(isbn)
@@ -288,7 +294,7 @@ module EnjuNdl
288
294
 
289
295
  private
290
296
 
291
- def get_title(doc)
297
+ def self.get_title(doc)
292
298
  title = {
293
299
  manifestation: doc.xpath('//dc:title/rdf:Description/rdf:value').collect(&:content).join(' '),
294
300
  transcription: doc.xpath('//dc:title/rdf:Description/dcndl:transcription').collect(&:content).join(' '),
@@ -302,7 +308,7 @@ module EnjuNdl
302
308
  title
303
309
  end
304
310
 
305
- def get_creators(doc)
311
+ def self.get_creators(doc)
306
312
  creators = []
307
313
  doc.xpath('//dcterms:creator/foaf:Agent').each do |creator|
308
314
  creators << {
@@ -314,7 +320,7 @@ module EnjuNdl
314
320
  creators
315
321
  end
316
322
 
317
- def get_subjects(doc)
323
+ def self.get_subjects(doc)
318
324
  subjects = []
319
325
  doc.xpath('//dcterms:subject/rdf:Description').each do |subject|
320
326
  subjects << {
@@ -325,7 +331,7 @@ module EnjuNdl
325
331
  subjects
326
332
  end
327
333
 
328
- def get_classifications(doc)
334
+ def self.get_classifications(doc)
329
335
  classifications = []
330
336
  doc.xpath('//dcterms:subject[@rdf:resource]').each do |classification|
331
337
  classifications << {
@@ -335,13 +341,13 @@ module EnjuNdl
335
341
  classifications
336
342
  end
337
343
 
338
- def get_language(doc)
344
+ def self.get_language(doc)
339
345
  # TODO: 言語が複数ある場合
340
346
  language = doc.at('//dcterms:language[@rdf:datatype="http://purl.org/dc/terms/ISO639-2"]').try(:content)
341
347
  language.downcase if language
342
348
  end
343
349
 
344
- def get_publishers(doc)
350
+ def self.get_publishers(doc)
345
351
  publishers = []
346
352
  doc.xpath('//dcterms:publisher/foaf:Agent').each do |publisher|
347
353
  publishers << {
@@ -353,7 +359,7 @@ module EnjuNdl
353
359
  publishers
354
360
  end
355
361
 
356
- def get_extent(doc)
362
+ def self.get_extent(doc)
357
363
  extent = doc.at('//dcterms:extent').try(:content)
358
364
  value = { start_page: nil, end_page: nil, height: nil }
359
365
  if extent
@@ -371,7 +377,7 @@ module EnjuNdl
371
377
  value
372
378
  end
373
379
 
374
- def create_series_statement(doc, manifestation)
380
+ def self.create_series_statement(doc, manifestation)
375
381
  series = series_title = {}
376
382
  series[:title] = doc.at('//dcndl:seriesTitle/rdf:Description/rdf:value').try(:content)
377
383
  series[:title_transcription] = doc.at('//dcndl:seriesTitle/rdf:Description/dcndl:transcription').try(:content)
@@ -398,8 +404,8 @@ module EnjuNdl
398
404
  manifestation
399
405
  end
400
406
 
401
- def format_query(query)
402
- Addressable::URI.encode(query.to_s.tr(' ', ' '))
407
+ def self.format_query(query)
408
+ URI.escape(query.to_s.tr(' ', ' '))
403
409
  end
404
410
  end
405
411
 
@@ -1,23 +1,26 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module EnjuNdl
3
- module Crd
4
- def self.included(base)
5
- base.extend ClassMethods
6
- end
4
+ module EnjuQuestion
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ def self.crd_per_page
9
+ 5
10
+ end
7
11
 
8
- module ClassMethods
9
- def get_crd_response(options)
12
+ def self.get_crd_response(options)
10
13
  params = { query_logic: 1, results_get_position: 1, results_num: 200, sort: 10 }.merge(options)
11
14
  query = []
12
15
  query << "01_#{params[:query_01].to_s.tr(' ', ' ')}" if params[:query_01]
13
16
  query << "02_#{params[:query_02].to_s.tr(' ', ' ')}" if params[:query_02]
14
17
  delimiter = '.'
15
- url = "http://crd.ndl.go.jp/refapi/servlet/refapi.RSearchAPI?query=#{Addressable::URI.encode(query.join(delimiter))}&query_logic=#{params[:query_logic]}&results_get_position=#{params[:results_get_position]}&results_num=#{params[:results_num]}&sort=#{params[:sort]}"
18
+ url = "http://crd.ndl.go.jp/refapi/servlet/refapi.RSearchAPI?query=#{URI.escape(query.join(delimiter))}&query_logic=#{params[:query_logic]}&results_get_position=#{params[:results_get_position]}&results_num=#{params[:results_num]}&sort=#{params[:sort]}"
16
19
 
17
- xml = open(url).read.to_s
20
+ open(url).read.to_s
18
21
  end
19
22
 
20
- def search_crd(options)
23
+ def self.search_crd(options)
21
24
  params = { page: 1 }.merge(options)
22
25
  crd_page = params[:page].to_i
23
26
  crd_page = 1 if crd_page <= 0
@@ -0,0 +1,14 @@
1
+ class JpnoRecord < ApplicationRecord
2
+ belongs_to :manifestation
3
+ end
4
+
5
+ # == Schema Information
6
+ #
7
+ # Table name: jpno_records
8
+ #
9
+ # id :bigint not null, primary key
10
+ # body :string not null
11
+ # manifestation_id :bigint not null
12
+ # created_at :datetime not null
13
+ # updated_at :datetime not null
14
+ #
@@ -0,0 +1,14 @@
1
+ class NdlBibIdRecord < ApplicationRecord
2
+ belongs_to :manifestation
3
+ end
4
+
5
+ # == Schema Information
6
+ #
7
+ # Table name: ndl_bib_id_records
8
+ #
9
+ # id :bigint not null, primary key
10
+ # body :string not null
11
+ # manifestation_id :bigint not null
12
+ # created_at :datetime not null
13
+ # updated_at :datetime not null
14
+ #
@@ -0,0 +1,14 @@
1
+ class NdlaRecord < ApplicationRecord
2
+ belongs_to :agent
3
+ end
4
+
5
+ # == Schema Information
6
+ #
7
+ # Table name: ndla_records
8
+ #
9
+ # id :bigint not null, primary key
10
+ # agent_id :bigint
11
+ # body :string not null
12
+ # created_at :datetime not null
13
+ # updated_at :datetime not null
14
+ #
@@ -0,0 +1,10 @@
1
+ class CreateJpnoRecords < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :jpno_records do |t|
4
+ t.string :body, index: {unique: true}, null: false
5
+ t.references :manifestation, foreign_key: true, null: false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateNdlaRecords < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :ndla_records do |t|
4
+ t.references :agent, foreign_key: true
5
+ t.string :body, null: false, index: {unique: true}
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateNdlBibIdRecords < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :ndl_bib_id_records do |t|
4
+ t.string :body, index: {unique: true}, null: false
5
+ t.references :manifestation, foreign_key: true, null: false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -1,30 +1,10 @@
1
- require "enju_ndl/engine"
1
+ require 'enju_ndl/engine'
2
2
  require 'open-uri'
3
- require 'enju_ndl/ndl_search'
4
- require 'enju_ndl/crd'
5
3
 
6
4
  module EnjuNdl
7
- module ActsAsMethods
8
- def self.included(base)
9
- base.extend ClassMethods
10
- end
11
-
12
- module ClassMethods
13
- def enju_ndl_ndl_search
14
- include EnjuNdl::NdlSearch
15
- end
16
-
17
- def enju_ndl_crd
18
- include EnjuNdl::Crd
19
- end
20
- end
21
- end
22
-
23
5
  class RecordNotFound < StandardError
24
6
  end
25
7
 
26
8
  class InvalidIsbn < StandardError
27
9
  end
28
10
  end
29
-
30
- ActiveRecord::Base.send :include, EnjuNdl::ActsAsMethods