relaton-jis 1.14.1 → 1.14.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: 29e1df903781ffa5a3c9e55bacefef03762c52d6a7df32a7fa8d28e7addc3403
4
- data.tar.gz: 480d6ddb9669c3fd8182cb5bd651c8ce695c5915e7bf82473abbe805dcbca155
3
+ metadata.gz: a6a4ecb8042069c8babc406d37ee36702fa28bb6efe4d4bdbc60c48ed7fc6599
4
+ data.tar.gz: 45ee95535b80261e3ad03f76a8025b86b9a4854509f2aab94056b6e438e38b6e
5
5
  SHA512:
6
- metadata.gz: 6431d5d67f17fa216d966a4116fcd03b8b13fd6fcbf019c02fd1abf4caa928598f544f4fcce30cb2b0ba0b6aaa81b329c5443f1b215bfcfd81aa6dfe7670a1ee
7
- data.tar.gz: 788e254613d82c07372c3ac3e13df715ee0f6f1ce71b0334ee8b1fdc577821eae6d2600976a1e91488076a69fcea8a696f123e929e6ffb390ef3e0fa845e62de
6
+ metadata.gz: c60b2041b0c812cafb40f3f96ab6d253a21f4e7381422551a702cba2ab9b84a2f2f03f1f05aaad6bcd187eaa95d097bf947fc142dcee142d6c2c73f4011fabe4
7
+ data.tar.gz: 52bfca55bb5bf3e49cb2f26d83d6a8068efb2a112676bfd9450248cbd7aa6e9834f1b96ff5da976c84013adbd846189d89b90bcb5f85ec543776497c60bf6a4d
@@ -16,7 +16,8 @@ module RelatonJis
16
16
  agent = Mechanize.new
17
17
  resp = agent.post "#{SOURCE}0010/searchByKeyword", search_type: "JIS", keyword: code
18
18
  disp = JSON.parse resp.body
19
- raise RelatonBib::RequestError, "No results found for #{code}" if disp["disp_screen"].nil?
19
+ # raise RelatonBib::RequestError, "No results found for #{code}" if disp["disp_screen"].nil?
20
+ return if disp["disp_screen"].nil?
20
21
 
21
22
  result = agent.get "#{SOURCE}#{disp['disp_screen']}/index"
22
23
  HitCollection.new code, year, result: result.xpath("//div[@class='blockGenaral']")
@@ -32,11 +33,15 @@ module RelatonJis
32
33
  #
33
34
  # @return [RelatonJis::BibliographicItem, nil] JIS document
34
35
  #
35
- def get(ref, year = nil, opts = {})
36
+ def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
36
37
  code = ref.sub(/\s\((all parts|規格群)\)/, "")
37
38
  opts[:all_parts] ||= !$1.nil?
38
39
  warn "[relaton-jis] (\"#{ref}\") fetching..."
39
40
  hits = search(code, year)
41
+ unless hits
42
+ hint [], ref, year
43
+ return
44
+ end
40
45
  result = opts[:all_parts] ? hits.find_all_parts : hits.find
41
46
  if result.is_a? RelatonJis::BibliographicItem
42
47
  warn "[relaton-jis] (\"#{ref}\") found #{result.docidentifier[0].id}"
@@ -23,10 +23,10 @@ module RelatonJis
23
23
  #
24
24
  # @return [Boolean] true if hit matches reference
25
25
  #
26
- def match?(ref_parts, year = nil, all_parts: false) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
26
+ def eq?(ref_parts, year = nil, all_parts: false) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
27
27
  id_parts[:code].include?(ref_parts[:code]) &&
28
28
  (all_parts || (ref_parts[:part].nil? || ref_parts[:part] == id_parts[:part])) &&
29
- (all_parts || year.nil? || year == id_parts[:year]) &&
29
+ (year.nil? || year == id_parts[:year]) &&
30
30
  ((ref_parts[:expl].nil? || !id_parts[:expl].nil?) &&
31
31
  (ref_parts[:expl_num].nil? || ref_parts[:expl_num] == id_parts[:expl_num])) &&
32
32
  ((ref_parts[:amd].nil? || !id_parts[:amd].nil?) &&
@@ -18,30 +18,55 @@ module RelatonJis
18
18
  # @return [RelatonJis::BibliographicItem, Array<Strig>] hash with bib ot array of missed years
19
19
  #
20
20
  def find
21
+ ref_year = year || ref_parts[:year]
22
+ if ref_year
23
+ find_by_year ref_year
24
+ else
25
+ find_all_years
26
+ end
27
+ end
28
+
29
+ def find_by_year(ref_year)
21
30
  missed_years = []
22
- y = year || ref_parts[:year]
23
31
  @array.each do |hit|
24
- return hit.fetch if hit.match? ref_parts, y
32
+ return hit.fetch if hit.eq? ref_parts, ref_year
25
33
 
26
- missed_years << hit.id_parts[:year] if y && hit.match?(ref_parts)
34
+ missed_years << hit.id_parts[:year] if hit.eq?(ref_parts)
27
35
  end
28
36
  missed_years
29
37
  end
30
38
 
31
- def find_all_parts
32
- hits = @array.select { |hit| hit.match? ref_parts, year, all_parts: true }
39
+ def find_all_years # rubocop:disable Metrics/AbcSize
40
+ hits = @array.select { |hit| hit.eq? ref_parts }
41
+ item = hits.max_by { |i| i.id_parts[:year].to_i }.fetch
42
+ item_id = item.docidentifier.first.id
43
+ parent = item.to_most_recent_reference
44
+ hits.each do |hit|
45
+ next if hit.hit[:id] == item_id
46
+
47
+ parent.relation << create_relation(hit)
48
+ end
49
+ parent
50
+ end
51
+
52
+ def find_all_parts # rubocop:disable Metrics/AbcSize
53
+ hits = @array.select { |hit| hit.eq? ref_parts, all_parts: true }
33
54
  item = hits.min_by { |i| i.id_parts[:part].to_i }.fetch.to_all_parts
34
55
  hits.each do |hit|
35
56
  next if hit.hit[:id] == item.docidentifier.first.id
36
57
 
37
- docid = RelatonBib::DocumentIdentifier.new id: hit.hit[:id], type: "JIS", primary: true
38
- fref = RelatonBib::FormattedRef.new content: hit.hit[:id]
39
- bibitem = BibliographicItem.new docid: [docid], formattedref: fref
40
- item.relation << RelatonBib::DocumentRelation.new(type: "instance", bibitem: bibitem)
58
+ item.relation << create_relation(hit)
41
59
  end
42
60
  item
43
61
  end
44
62
 
63
+ def create_relation(hit)
64
+ docid = RelatonBib::DocumentIdentifier.new id: hit.hit[:id], type: "JIS", primary: true
65
+ fref = RelatonBib::FormattedRef.new content: hit.hit[:id]
66
+ bibitem = BibliographicItem.new docid: [docid], formattedref: fref
67
+ RelatonBib::DocumentRelation.new(type: "instance", bibitem: bibitem)
68
+ end
69
+
45
70
  #
46
71
  # Return parts of reference
47
72
  #
@@ -104,10 +104,10 @@ module RelatonJis
104
104
 
105
105
  def fetch_doctype
106
106
  case document_id
107
- when /JIS\s[A-Z]\s[\w-]+:\d{4}\/AMD/ then "amendment"
107
+ when /JIS\s[A-Z]\s[\w-]+:\d{4}\/AMENDMENT/ then "amendment"
108
108
  when /JIS\s[A-Z]\s[\w-]+/ then "japanese-industrial-standard"
109
- when /TR\s[\w-]+/ then "technical-report"
110
- when /TS\s[\w-]+/ then "technical-specification"
109
+ when /TR[\s\/][\w-]+/ then "technical-report"
110
+ when /TS[\s\/][\w-]+/ then "technical-specification"
111
111
  end
112
112
  end
113
113
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonJis
4
- VERSION = "1.14.1"
4
+ VERSION = "1.14.2"
5
5
  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.14.1
4
+ version: 1.14.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-04-04 00:00:00.000000000 Z
11
+ date: 2023-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.1.6
106
+ rubygems_version: 3.3.26
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: 'RelatonJis: retrieve IETF Standards for bibliographic use using the BibliographicItem