relaton-iso 1.7.4 → 1.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 285f112d9488263e9befd0b7cf1edc555be821457c5704a96b4619c3d0140bce
4
- data.tar.gz: 71425bbdfcea77012c480e000787c55084380816adb627d51f61d3335b6e64a0
3
+ metadata.gz: f0c5bc4d61a17fbf55ecc1d68d689198c181c5d68924b1d4cf73f4d7e166ff14
4
+ data.tar.gz: 1621f2d080eea7e977811a1616e80137317de4339fd9820e69f7245d996b3619
5
5
  SHA512:
6
- metadata.gz: 488b4d385f6a18c9e5cf8199e71b8d5a9a10e1068959f98c789ffaf95d634b12c68baaad64d7145236b379f2f103e44ee2958c8091d0312d97d67d5f378fac0b
7
- data.tar.gz: 8a1ba31f5b5b809edc081eade7b9c142d4a33b74768f5eca38c92312e48745dcc6022df491a06c3fe7ee93a544022c113ee733a403940f297d3ed63b400a9405
6
+ metadata.gz: 4842a83c61845dc60985b5c916902d21b423be5c6eeeaf27f0d31e6db7badb63accfb48f67e64287cc77685ab23a373a17015cd15df132d7cd18f711ea30cdc6
7
+ data.tar.gz: 3729fbb3e1bdfe2406c1c80e6ad839f9f06b17f9270e5e7c19117ae943e5e750300073c2d701458c472e65a8bd4e56ec086a79b83873ec5c7ac8161cf7f18ca2
data/README.adoc CHANGED
@@ -59,6 +59,18 @@ item.docidentifier
59
59
  => "urn:iso:std:iso-ts:ts:19115:-3:stage-90.92:ed-1:en,fr"
60
60
  ----
61
61
 
62
+ === Search for ISO/IEC Directives
63
+
64
+ The ISO/IEC Derectives are stored in a static cache in a relaton gem. It needs to use the relaton gem to fetch the ISO/IEC Directives. Folloving reaferences are allowed to fetch:
65
+
66
+ - ISO/IEC DIR 1 - Procedures for the technical work
67
+ - ISO/IEC DIR 1 IEC SUP - Procedures for the technical work – Procedures specific to IEC
68
+ - ISO/IEC DIR 1 ISO SUP - Consolidated ISO Supplement -- Procedures specific to ISO
69
+ - ISO/IEC DIR 2 IEC - Principles and rules for the structure and drafting of ISO and IEC documents
70
+ - ISO/IEC DIR 2 ISO - Principles and rules for the structure and drafting of ISO and IEC documents
71
+ - ISO/IEC DIR IEC SUP - Procedures specific to IEC
72
+ - ISO/IEC DIR JTC 1 SUP - Procedures specific to JTC 1
73
+
62
74
  === XML serialization
63
75
 
64
76
  Possible options:
@@ -3,6 +3,9 @@
3
3
  module RelatonIso
4
4
  # Hit.
5
5
  class Hit < RelatonBib::Hit
6
+ # @return [RelatonIsoBib::IsoBibliographicItem]
7
+ attr_accessor :fetch
8
+
6
9
  # Parse page.
7
10
  # @param lang [String, NilClass]
8
11
  # @return [RelatonIso::IsoBibliographicItem]
@@ -10,25 +10,7 @@ module RelatonIso
10
10
  # @param text [String] reference to search
11
11
  def initialize(text)
12
12
  super
13
- %r{\s(?<num>\d+)(-(?<part>[\d-]+))?} =~ text
14
- http = Net::HTTP.new "www.iso.org", 443
15
- http.use_ssl = true
16
- search = ["status=ENT_ACTIVE,ENT_PROGRESS,ENT_INACTIVE,ENT_DELETED"]
17
- search << "docNumber=#{num}"
18
- search << "docPartNo=#{part}" if part
19
- q = search.join "&"
20
- resp = http.get("/cms/render/live/en/sites/isoorg.advancedSearch.do?#{q}",
21
- "Accept" => "application/json, text/plain, */*")
22
- return if resp.body.empty?
23
-
24
- json = JSON.parse resp.body
25
- @array = json["standards"].map { |h| Hit.new h, self }.sort! do |a, b|
26
- if a.sort_weight == b.sort_weight
27
- (parse_date(b.hit) - parse_date(a.hit)).to_i
28
- else
29
- a.sort_weight - b.sort_weight
30
- end
31
- end
13
+ @array = text.match?(/^ISO\sTC\s184\/SC\s?4/) ? fetch_github : fetch_iso
32
14
  end
33
15
 
34
16
  # @param lang [String, NilClass]
@@ -54,6 +36,52 @@ module RelatonIso
54
36
 
55
37
  private
56
38
 
39
+ #
40
+ # Fetch document from GitHub repository
41
+ #
42
+ # @return [Array<RelatonIso::Hit]
43
+ #
44
+ def fetch_github
45
+ ref = text.gsub(/[\s\/]/, "_").upcase
46
+ url = "https://raw.githubusercontent.com/relaton/relaton-data-iso/main/data/#{ref}.yaml"
47
+ resp = Net::HTTP.get_response URI(url)
48
+ return [] unless resp.code == "200"
49
+
50
+ hash = YAML.safe_load resp.body
51
+ bib_hash = RelatonIsoBib::HashConverter.hash_to_bib hash
52
+ bib = RelatonIsoBib::IsoBibliographicItem.new **bib_hash
53
+ hit = Hit.new({ "docRef" => text }, self)
54
+ hit.fetch = bib
55
+ [hit]
56
+ end
57
+
58
+ #
59
+ # Fetch hits from iso.org
60
+ #
61
+ # @return [Array<RelatonIso::Hit>]
62
+ #
63
+ def fetch_iso
64
+ %r{\s(?<num>\d+)(-(?<part>[\d-]+))?} =~ text
65
+ http = Net::HTTP.new "www.iso.org", 443
66
+ http.use_ssl = true
67
+ search = ["status=ENT_ACTIVE,ENT_PROGRESS,ENT_INACTIVE,ENT_DELETED"]
68
+ search << "docNumber=#{num}"
69
+ search << "docPartNo=#{part}" if part
70
+ q = search.join "&"
71
+ resp = http.get("/cms/render/live/en/sites/isoorg.advancedSearch.do?#{q}",
72
+ "Accept" => "application/json, text/plain, */*")
73
+ return if resp.body.empty?
74
+
75
+ json = JSON.parse resp.body
76
+ json["standards"].map { |h| Hit.new h, self }.sort! do |a, b|
77
+ if a.sort_weight == b.sort_weight
78
+ (parse_date(b.hit) - parse_date(a.hit)).to_i
79
+ else
80
+ a.sort_weight - b.sort_weight
81
+ end
82
+ end
83
+ end
84
+
57
85
  # @param hit [Hash]
58
86
  # @return [Date]
59
87
  def parse_date(hit)
@@ -26,32 +26,13 @@ module RelatonIso
26
26
  # return actual reference with year
27
27
  # @return [String] Relaton XML serialisation of reference
28
28
  def get(ref, year = nil, opts = {})
29
- opts[:ref] = ref.gsub(/\u2013/, "-")
30
-
31
- %r{
32
- ^(?<code1>[^\s]+\s[^\/]+) # match code
33
- /?
34
- (?<corr>(Amd|DAmd|(CD|WD|AWI|NP)\sAmd|Cor|CD\sCor|FDAmd|PRF\sAmd)\s\d+ # correction name
35
- :?(\d{4})?(/Cor\s\d+:\d{4})?) # match correction year
36
- }x =~ opts[:ref]
37
- code = code1 || opts[:ref]
38
-
39
- if year.nil?
40
- /^(?<code1>[^\s]+(\s\w+)?\s[\d-]+)(:(?<year1>\d{4}))?(?<code2>\s\w+)?/ =~ code
41
- /:(?<year2>\d{4})/ =~ corr
42
- unless code1.nil?
43
- code = code1 + code2.to_s
44
- year = year2 || year1
45
- end
46
- end
47
- %r{\s(?<num>\d+)(-(?<part>[\d-]+))?} =~ code
48
- opts[:part] = part
49
- opts[:num] = num
50
- opts[:corr] = corr
51
- opts[:all_parts] ||= !part && opts[:all_parts].nil? && code2.nil?
52
- if %r[^ISO/IEC DIR].match? code
53
- return RelatonIec::IecBibliography.get(code, year, opts)
54
- end
29
+ code = ref.gsub(/\u2013/, "-")
30
+ %r{\s(?<num>\d+)(-(?<part>[\d-]+))?(:(?<year1>\d{4}))?} =~ code
31
+ year ||= year1
32
+ opts[:all_parts] ||= !part && opts[:all_parts].nil? # && code2.nil?
33
+ # if %r[^ISO/IEC DIR].match? code
34
+ # return RelatonIec::IecBibliography.get(code, year, opts)
35
+ # end
55
36
 
56
37
  ret = isobib_get1(code, year, opts)
57
38
  return nil if ret.nil?
@@ -95,7 +76,7 @@ module RelatonIso
95
76
  # @param opts [Hash]
96
77
  # @return [Array<RelatonIso::Hit>]
97
78
  def isobib_search_filter(code, opts)
98
- warn "[relaton-iso] (\"#{opts[:ref]}\") fetching..."
79
+ warn "[relaton-iso] (\"#{code}\") fetching..."
99
80
  result = search(code)
100
81
  res = search_code result, code, opts
101
82
  return res unless res.empty?
@@ -140,17 +121,24 @@ module RelatonIso
140
121
  # @param opts [Hash]
141
122
  # @return [RelatonIso::HitCollection]
142
123
  def search_code(result, code, opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
143
- ref_regex = %r{^#{code}(?!-)}
144
- corr_regex = %r{^#{code}[\w-]*(:\d{4})?/#{opts[:corr]}}
145
- no_corr_regex = %r{^#{code}[\w-]*(:\d{4})?/}
124
+ code1, part1, corr1, coryear1 = ref_components code
146
125
  result.select do |i|
147
- (opts[:all_parts] || i.hit["docRef"] =~ ref_regex) && (
148
- opts[:corr] && corr_regex =~ i.hit["docRef"] ||
149
- !opts[:corr] && no_corr_regex !~ i.hit["docRef"]
150
- )
126
+ code2, part2, corr2, coryear2 = ref_components i.hit["docRef"]
127
+ code1 == code2 && (!part1 || part1 == part2) &&
128
+ corr1 == corr2 && (!coryear1 || coryear1 == coryear2)
151
129
  end
152
130
  end
153
131
 
132
+ def ref_components(ref)
133
+ %r{
134
+ ^(?<code>ISO(?:\s|\/)[^-\/:]+)
135
+ (?:-(?<part>[^:\/]+))?
136
+ (?::\d{4})?
137
+ (?:\/(?<corr>\w+(?:\s\w+)?\s\d+)(?:(?<coryear>\d{4}))?)?
138
+ }x =~ ref
139
+ [code, part, corr, coryear]
140
+ end
141
+
154
142
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
155
143
 
156
144
  # Sort through the results from RelatonIso, fetching them three at a time,
@@ -188,7 +176,7 @@ module RelatonIso
188
176
  result = isobib_search_filter(code, opts) || return
189
177
  ret = isobib_results_filter(result, year, opts)
190
178
  if ret[:ret]
191
- warn "[relaton-iso] (\"#{opts[:ref]}\") found #{ret[:ret].docidentifier.first.id}"
179
+ warn "[relaton-iso] (\"#{code}\") found #{ret[:ret].docidentifier.first.id}"
192
180
  ret[:ret]
193
181
  else
194
182
  fetch_ref_err(code, year, ret[:years])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonIso
4
- VERSION = "1.7.4"
4
+ VERSION = "1.7.5"
5
5
  end
data/relaton_iso.gemspec CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  # spec.add_development_dependency "debase"
31
31
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
32
32
  spec.add_development_dependency "pry-byebug"
33
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
34
  spec.add_development_dependency "rspec", "~> 3.0"
35
35
  # spec.add_development_dependency "ruby-debug-ide"
36
36
  spec.add_development_dependency "simplecov"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-19 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement