relaton-jis 1.16.0 → 1.16.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6227e97046cb6fa42f7a00f120713279fd0dc673b1cbee2ecbf550e595fb46dd
4
- data.tar.gz: f952fc50ae5a6fdc7b839af1956457d9c4c6c1041e61557b2f7493a8b6b0c96f
3
+ metadata.gz: 0f553d8895e1407f6efa8f149be93c2923b89a6a8e8c1a104098b9b8c3a56055
4
+ data.tar.gz: ec304140ac64f7173e592661d0f183d1b1285d09164fc4b472d53154758f045b
5
5
  SHA512:
6
- metadata.gz: 227152cc685526b2375b53de5201a3a819b33deec0391870513f9f7eca493030809ba92a8137323c795724800821b530d651e1f1ccf48bfb1bae19b1c2d39832
7
- data.tar.gz: e67f10b5df5c9305b98b4627e4f9801751c7bd13a1545997f08d7d1d0f6717939c42c957a84535e05fc364e2ba08fb364432c7e2e1cf4e04b5bf96897c19f2b5
6
+ metadata.gz: df6a1896c95ab8245adc1647b530c7fa821bf1f7c9da679805005f28acf396b8c6acc33ed63ad80fe1dfc85635fce7bf287da13d7a9c7ad32fc7cbd52f0bd7c2
7
+ data.tar.gz: 78dfe40b2cdcb55c4ae4215a4bd3ad95f6181cd16284956963d00501c4527d5945b7f806e6206a637d93e6ae029ca3e5df893713020328407e95547b8a9499f4
data/README.adoc CHANGED
@@ -22,13 +22,24 @@ If bundler is not being used to manage dependencies, install the gem by executin
22
22
 
23
23
  == Usage
24
24
 
25
- === Search for standards using keywords
25
+ === Configuration
26
+
27
+ Configuration is optional. The available option is `logger` which is a `Logger` instance. By default, the logger is `Logger.new($stderr)` with `Logger::WARN` level. To change the logger level, use `RelatonJis.configure` block.
26
28
 
27
29
  [source,ruby]
28
30
  ----
29
31
  require 'relaton_jis'
30
32
  => true
31
33
 
34
+ RelatonJis.configure do |config|
35
+ config.logger.level = Logger::DEBUG
36
+ end
37
+ ----
38
+
39
+ === Search for standards using keywords
40
+
41
+ [source,ruby]
42
+ ----
32
43
  hit_collection = RelatonJis::Bibliography.search("JIS X 0208")
33
44
  => <RelatonJis::HitCollection:0x00000000018858 @ref=JIS X 0208 @fetched=false>
34
45
 
@@ -54,14 +65,14 @@ item.docidentifier
54
65
  [source,ruby]
55
66
  ----
56
67
  item = RelatonJis::Bibliography.get "JIS X 0208:1997"
57
- [relaton-jis] ("JIS X 0208:1997") fetching...
58
- [relaton-jis] ("JIS X 0208:1997") found JIS X 0208:1997
68
+ [relaton-jis] (JIS X 0208:1997) Fetching from webdesk.jsa.or.jp ...
69
+ [relaton-jis] (JIS X 0208:1997) Found: `JIS X 0208:1997`
59
70
  => #<RelatonJis::BibliographicItem:0x00007fe4478ecc08
60
71
  ...
61
72
 
62
73
  item = RelatonJis::Bibliography.get "JIS X 0208", "1997"
63
- [relaton-jis] ("JIS X 0208") fetching...
64
- [relaton-jis] ("JIS X 0208") found JIS X 0208:1997
74
+ [relaton-jis] (JIS X 0208) Fetching from webdesk.jsa.or.jp ...
75
+ [relaton-jis] (JIS X 0208) Found: `JIS X 0208:1997`
65
76
  => #<RelatonJis::BibliographicItem:0x00007fe436b49d90
66
77
  ...
67
78
 
@@ -14,13 +14,15 @@ module RelatonJis
14
14
  #
15
15
  def search(code, year = nil)
16
16
  agent = Mechanize.new
17
- resp = agent.post "#{SOURCE}0010/searchByKeyword", search_type: "JIS", keyword: code
17
+ resp = agent.post "#{SOURCE}0010/searchByKeyword", search_type: "JIS",
18
+ keyword: code
18
19
  disp = JSON.parse resp.body
19
20
  # raise RelatonBib::RequestError, "No results found for #{code}" if disp["disp_screen"].nil?
20
21
  return if disp["disp_screen"].nil?
21
22
 
22
23
  result = agent.get "#{SOURCE}#{disp['disp_screen']}/index"
23
- HitCollection.new code, year, result: result.xpath("//div[@class='blockGenaral']")
24
+ HitCollection.new code, year,
25
+ result: result.xpath("//div[@class='blockGenaral']")
24
26
  end
25
27
 
26
28
  #
@@ -36,7 +38,7 @@ module RelatonJis
36
38
  def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
37
39
  code = ref.sub(/\s\((all parts|規格群)\)/, "")
38
40
  opts[:all_parts] ||= !$1.nil?
39
- warn "[relaton-jis] (\"#{ref}\") fetching..."
41
+ Util.warn "(#{ref}) Fetching from webdesk.jsa.or.jp ..."
40
42
  hits = search(code, year)
41
43
  unless hits
42
44
  hint [], ref, year
@@ -44,7 +46,7 @@ module RelatonJis
44
46
  end
45
47
  result = opts[:all_parts] ? hits.find_all_parts : hits.find
46
48
  if result.is_a? RelatonJis::BibliographicItem
47
- warn "[relaton-jis] (\"#{ref}\") found #{result.docidentifier[0].id}"
49
+ Util.warn "(#{ref}) Found: `#{result.docidentifier[0].id}`"
48
50
  return result
49
51
  end
50
52
  hint result, ref, year
@@ -58,12 +60,12 @@ module RelatonJis
58
60
  # @param [String, nil] year year to search
59
61
  #
60
62
  def hint(result, ref, year)
61
- warn "[relaton-jis] (\"#{ref}\") not found. The identifier must be " \
62
- "exactly as shown on the webdesk.jsa.or.jp website."
63
+ Util.warn "(#{ref}) Not found."
63
64
  if result.any?
64
- warn "[relaton-jis] (\"#{ref}\") TIP: No match for edition " \
65
- "year #{year}, but matches exist for #{result.uniq.join(', ')}."
65
+ Util.warn "(#{ref}) TIP: No match for edition year `#{year}`, " \
66
+ "but matches exist for `#{result.uniq.join('`, `')}`."
66
67
  end
68
+ nil
67
69
  end
68
70
  end
69
71
  end
@@ -0,0 +1,10 @@
1
+ module RelatonJis
2
+ module Config
3
+ include RelatonBib::Config
4
+ end
5
+ extend Config
6
+
7
+ class Configuration < RelatonBib::Configuration
8
+ PROGNAME = "relaton-jis".freeze
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module RelatonJis
2
+ module Util
3
+ extend RelatonBib::Util
4
+
5
+ def self.logger
6
+ RelatonJis.configuration.logger
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonJis
4
- VERSION = "1.16.0"
4
+ VERSION = "1.16.2"
5
5
  end
data/lib/relaton_jis.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  require "mechanize"
4
4
  require "relaton_iso_bib"
5
5
  require_relative "relaton_jis/version"
6
+ require_relative "relaton_jis/config"
7
+ require_relative "relaton_jis/util"
6
8
  require_relative "relaton_jis/bibliographic_item"
7
9
  require_relative "relaton_jis/xml_parser"
8
10
  require_relative "relaton_jis/hash_converter"
@@ -17,9 +19,9 @@ module RelatonJis
17
19
  # Returns hash of XML reammar
18
20
  # @return [String]
19
21
  def self.grammar_hash
20
- gem_path = File.expand_path "..", __dir__
21
- grammars_path = File.join gem_path, "grammars", "*"
22
- grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
23
- Digest::MD5.hexdigest grammars
22
+ # gem_path = File.expand_path "..", __dir__
23
+ # grammars_path = File.join gem_path, "grammars", "*"
24
+ # grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
25
+ Digest::MD5.hexdigest RelatonJis::VERSION + RelatonIsoBib::VERSION + RelatonBib::VERSION # grammars
24
26
  end
25
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-jis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-03 00:00:00.000000000 Z
11
+ date: 2023-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -60,11 +60,13 @@ files:
60
60
  - lib/relaton_jis.rb
61
61
  - lib/relaton_jis/bibliographic_item.rb
62
62
  - lib/relaton_jis/bibliography.rb
63
+ - lib/relaton_jis/config.rb
63
64
  - lib/relaton_jis/hash_converter.rb
64
65
  - lib/relaton_jis/hit.rb
65
66
  - lib/relaton_jis/hit_collection.rb
66
67
  - lib/relaton_jis/processor.rb
67
68
  - lib/relaton_jis/scraper.rb
69
+ - lib/relaton_jis/util.rb
68
70
  - lib/relaton_jis/version.rb
69
71
  - lib/relaton_jis/xml_parser.rb
70
72
  - relaton_jis.gemspec