relaton-iso 1.15.4 → 1.15.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: 849d2ed5597da449397be8d44059b7c88d799bb118ff53cb13abcb67b90ec98c
4
- data.tar.gz: 4084d1465fee0a3bc9062734d405eb97a1a28e18e866a473433026509a8907e1
3
+ metadata.gz: d8f96ec7677b17a7e89ca54cc7230eda13391749c404fcc8d95bca32ddb61d98
4
+ data.tar.gz: c74831929f8d4d276e1aae6c06990559e51bcc4ba1ea3c627fef33d141463612
5
5
  SHA512:
6
- metadata.gz: 800e61c17385335e14b7fa56d9d29031db9a43ce6d908fd21dcd841db1422c2addec5a78e2a44aad4ceb170754167b79530c891d97ae54aff519900bfdcc0ebb
7
- data.tar.gz: 00eb78136a9f91335f412d5af3d64fd83fce8d94b2fcce13e252dca09ac36eb2ec1e5fd3e025cda196be92f4d6fda49b17239f8bd4a6611ba7b177f0ecc302ab
6
+ metadata.gz: 80862ee504de862925e70c188ae40ed13001748f87f9af41aaad00e1e3e2b473779da64e0402ac920ac84af6318e19fe8ec6d73c7d6ff5b752b20f3fd0d2721c
7
+ data.tar.gz: e896e1986545b722df2393b075ce947d2ab00ca365249498b4a0e738ebcb9669475e72961e2ab90495181ce8ccd5af8df380d697b9433b335e013ab554ddf23a
data/Gemfile CHANGED
@@ -6,7 +6,10 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
  gemspec
7
7
 
8
8
  gem "byebug"
9
+ gem "equivalent-xml"
9
10
  gem "pry-byebug"
11
+ gem "rake", "~> 13.0"
12
+ gem "rspec", "~> 3.0"
10
13
  gem "rubocop"
11
14
  gem "rubocop-performance"
12
15
  gem "rubocop-rails"
data/README.adoc CHANGED
@@ -49,37 +49,11 @@ item = hit_collection[2].fetch
49
49
  ...
50
50
 
51
51
  item.docidentifier
52
- => [#<RelatonIso::DocumentIdentifier:0x00007fa8b7db1f20
53
- @id=
54
- #<Pubid::Iso::Identifier:0x00007fa8b7db2a60
55
- @base=#<Pubid::Iso::Identifier:0x00007fa8b7db2c68 @edition="1", @number="19115"@4, @part="1", @publisher="ISO", @year=2014>,
56
- @number="2"@21,
57
- @publisher="ISO",
58
- @stage=#<Pubid::Iso::Stage:0x00007fa8b7db20d8 @abbr=nil, @harmonized_code=#<Pubid::Iso::HarmonizedStageCode:0x00007fa8b7db2088 @stages=["60.60"]>>,
59
- @typed_stage=#<Pubid::Iso::TypedStage:0x00007fa8b7db2920 @type=#<Pubid::Iso::Type:0x00007fa8b7db26c8 @type=:amd>, @typed_stage=nil>,
60
- @year=2020>,
61
- @language=nil,
62
- @primary=true,
63
- @scope=nil,
64
- @script=nil,
65
- @type="ISO">,
66
- #<RelatonIso::DocumentIdentifier:0x00007fa8b7db1e80
67
- @id=
68
- #<Pubid::Iso::Identifier:0x00007fa8b7db2a60
69
- @base=#<Pubid::Iso::Identifier:0x00007fa8b7db2c68 @edition="1", @number="19115"@4, @part="1", @publisher="ISO", @year=2014>,
70
- @number="2"@21,
71
- @publisher="ISO",
72
- @stage=#<Pubid::Iso::Stage:0x00007fa8b7db20d8 @abbr=nil, @harmonized_code=#<Pubid::Iso::HarmonizedStageCode:0x00007fa8b7db2088 @stages=["60.60"]>>,
73
- @typed_stage=#<Pubid::Iso::TypedStage:0x00007fa8b7db2920 @type=#<Pubid::Iso::Type:0x00007fa8b7db26c8 @type=:amd>, @typed_stage=nil>,
74
- @year=2020>,
75
- @language=nil,
76
- @primary=nil,
77
- @scope=nil,
78
- @script=nil,
79
- @type="URN">]
52
+ => [#<RelatonIso::DocumentIdentifier:0x0000000112a23a88
53
+ ...
80
54
 
81
55
  item.docidentifier.detect { |di| di.type == "URN" }.id
82
- => "urn:iso:std:iso:19115:-1:ed-1:amd:2020:v2"
56
+ => "urn:iso:std:iso:19115:-1:ed-1:stage-60.60:amd:2020:v2"
83
57
  ----
84
58
 
85
59
  === Fetch document by reference and year
@@ -93,9 +67,9 @@ item = RelatonIso::IsoBibliography.get "ISO 19115:2003"
93
67
  ...
94
68
 
95
69
  item = RelatonIso::IsoBibliography.get "ISO 19115", "2003"
96
- [relaton-iso] ("ISO 19115") fetching from ISO...
97
- [relaton-iso] ("ISO 19115:2003") Found exact match.
98
- => #<RelatonIsoBib::IsoBibliographicItem:0x00007f8c828d3180
70
+ [relaton-iso] ("ISO 19115:2003") Fetching from ISO...
71
+ [relaton-iso] ("ISO 19115:2003") Found ("ISO 19115:2003").
72
+ => #<RelatonIsoBib::IsoBibliographicItem:0x0000000112c9ca80
99
73
  ...
100
74
 
101
75
  item.docidentifier[0].id
@@ -113,7 +87,7 @@ item = RelatonIso::IsoBibliography.get "ISO 19115"
113
87
  ...
114
88
 
115
89
  item.docidentifier[0].id
116
- => "ISO 19115:2003"
90
+ => "ISO 19115"
117
91
  ----
118
92
 
119
93
  === Fetch a part document
@@ -136,13 +110,13 @@ item.docidentifier[0].id
136
110
  ----
137
111
  item = RelatonIso::IsoBibliography.get "ISO 19115 (all parts)"
138
112
  [relaton-iso] ("ISO 19115") Fetching from ISO...
139
- [relaton-iso] ("ISO 19115") Found exact match.
113
+ [relaton-iso] ("ISO 19115") Found ("ISO 19115").
140
114
  => #<RelatonIsoBib::IsoBibliographicItem:0x00007f8ca216e118
141
115
  ...
142
116
 
143
117
  item = RelatonIso::IsoBibliography.get "ISO 19115", nil, all_parts: true
144
118
  [relaton-iso] ("ISO 19115") Fetching from ISO...
145
- [relaton-iso] ("ISO 19115") Found exact match.
119
+ [relaton-iso] ("ISO 19115") Found ("ISO 19115").
146
120
  => #<RelatonIsoBib::IsoBibliographicItem:0x00007f8c830f3d38
147
121
  ...
148
122
 
@@ -151,12 +125,12 @@ item.docidentifier[0].id
151
125
 
152
126
  item = RelatonIso::IsoBibliography.get "ISO 19115-1 (all parts)"
153
127
  [relaton-iso] ("ISO 19115") Fetching from ISO...
154
- [relaton-iso] ("ISO 19115") Found exact match.
128
+ [relaton-iso] ("ISO 19115") Found ("ISO 19115").
155
129
  => #<RelatonIsoBib::IsoBibliographicItem:0x00007f8c8290e5a0
156
130
 
157
131
  item = RelatonIso::IsoBibliography.get "ISO 19115-1", nil, all_parts: true
158
132
  [relaton-iso] ("ISO 19115") Fetching from ISO...
159
- [relaton-iso] ("ISO 19115") Found exact match.
133
+ [relaton-iso] ("ISO 19115") Found ("ISO 19115").
160
134
  => #<RelatonIsoBib::IsoBibliographicItem:0x00007f8c925355b8
161
135
  ...
162
136
 
@@ -217,35 +191,31 @@ item.to_xml note: [{ text: "Note", type: "note" }]
217
191
  [source,ruby]
218
192
  ----
219
193
  item.title lang: 'en'
220
- => #<RelatonBib::TypedTitleStringCollection:0x00007fa8b7f47c90
194
+ => #<RelatonBib::TypedTitleStringCollection:0x0000000112783fd0
221
195
  @array=
222
- [#<RelatonBib::TypedTitleString:0x00007fa8b7be8a40
223
- @title=#<RelatonBib::FormattedString:0x00007fa8b7be87c0 @content="Geographic information", @format="text/plain", @language=["en"], @script=["Latn"]>,
196
+ [#<RelatonBib::TypedTitleString:0x00000001138e2380
197
+ @title=#<RelatonBib::FormattedString:0x0000000112d496b8 @content="Geographic information", @format="text/plain", @language=["en"], @script=["Latn"]>,
224
198
  @type="title-intro">,
225
- #<RelatonBib::TypedTitleString:0x00007fa8b7be84a0
226
- @title=#<RelatonBib::FormattedString:0x00007fa8b7be83d8 @content="Metadata", @format="text/plain", @language=["en"], @script=["Latn"]>,
199
+ #<RelatonBib::TypedTitleString:0x00000001138e1f70
200
+ @title=#<RelatonBib::FormattedString:0x0000000112d495c8 @content="Metadata", @format="text/plain", @language=["en"], @script=["Latn"]>,
227
201
  @type="title-main">,
228
- #<RelatonBib::TypedTitleString:0x00007fa8b7be8130
202
+ #<RelatonBib::TypedTitleString:0x00000001138e1d68
229
203
  @title=
230
- #<RelatonBib::FormattedString:0x00007fa8b7be8018
231
- @content="Geographic information – Metadata",
232
- @format="text/plain",
233
- @language=["en"],
234
- @script=["Latn"]>,
204
+ #<RelatonBib::FormattedString:0x0000000112d49488 @content="Geographic information – Metadata", @format="text/plain", @language=["en"], @script=["Latn"]>,
235
205
  @type="main">]>
236
206
 
237
207
  item.title lang: 'fr'
238
- => #<RelatonBib::TypedTitleStringCollection:0x00007fa8b7bcb4b8
208
+ => #<RelatonBib::TypedTitleStringCollection:0x0000000113067458
239
209
  @array=
240
- [#<RelatonBib::TypedTitleString:0x00007fa8b7be3ea0
241
- @title=#<RelatonBib::FormattedString:0x00007fa8b7be3dd8 @content="Information géographique", @format="text/plain", @language=["fr"], @script=["Latn"]>,
210
+ [#<RelatonBib::TypedTitleString:0x00000001138e1c28
211
+ @title=#<RelatonBib::FormattedString:0x0000000112d49438 @content="Information géographique", @format="text/plain", @language=["fr"], @script=["Latn"]>,
242
212
  @type="title-intro">,
243
- #<RelatonBib::TypedTitleString:0x00007fa8b7be3ba8
244
- @title=#<RelatonBib::FormattedString:0x00007fa8b7be3b58 @content="Métadonnées", @format="text/plain", @language=["fr"], @script=["Latn"]>,
213
+ #<RelatonBib::TypedTitleString:0x00000001138e1b10
214
+ @title=#<RelatonBib::FormattedString:0x0000000112d49398 @content="Métadonnées", @format="text/plain", @language=["fr"], @script=["Latn"]>,
245
215
  @type="title-main">,
246
- #<RelatonBib::TypedTitleString:0x00007fa8b7be38d8
216
+ #<RelatonBib::TypedTitleString:0x00000001138e1908
247
217
  @title=
248
- #<RelatonBib::FormattedString:0x00007fa8b7be3860
218
+ #<RelatonBib::FormattedString:0x0000000112d491b8
249
219
  @content="Information géographique – Métadonnées",
250
220
  @format="text/plain",
251
221
  @language=["fr"],
@@ -254,10 +224,9 @@ item.title lang: 'fr'
254
224
 
255
225
  item = RelatonIso::IsoBibliography.get "ISO 19115:2003"
256
226
  [relaton-iso] ("ISO 19115:2003") Fetching from ISO...
257
- [relaton-iso] ("ISO 19115:2003") Found exact match.
227
+ [relaton-iso] ("ISO 19115:2003") Found ("ISO 19115:2003").
258
228
  => #<RelatonIsoBib::IsoBibliographicItem:0x00007fa8870b69e0
259
229
 
260
- item.abstract lang: 'en'
261
230
  item.abstract lang: 'en'
262
231
  => #<RelatonBib::FormattedString:0x00007fa8870b4f78
263
232
  @content=
@@ -274,13 +243,13 @@ Each ISO document has `src` type link and optional `obp`, `rss`, and `pub` link
274
243
  [source,ruby]
275
244
  ----
276
245
  item.link
277
- => [#<RelatonBib::TypedUri:0x00007fa8870ac5a8
278
- @content=#<Addressable::URI:0xcc6514 URI:https://www.iso.org/standard/26020.html>,
246
+ => [#<RelatonBib::TypedUri:0x0000000112d66c40
247
+ @content=#<Addressable::URI:0x93d71c URI:https://www.iso.org/standard/26020.html>,
279
248
  @language=nil,
280
249
  @script=nil,
281
250
  @type="src">,
282
- #<RelatonBib::TypedUri:0x00007fa8870a7490
283
- @content=#<Addressable::URI:0xcc6528 URI:https://www.iso.org/contents/data/standard/02/60/26020.detail.rss>,
251
+ #<RelatonBib::TypedUri:0x0000000112d66920
252
+ @content=#<Addressable::URI:0x93d730 URI:https://www.iso.org/contents/data/standard/02/60/26020.detail.rss>,
284
253
  @language=nil,
285
254
  @script=nil,
286
255
  @type="rss">]
@@ -0,0 +1,26 @@
1
+ module RelatonIso
2
+ module Config
3
+ def configure
4
+ yield configuration if block_given?
5
+ end
6
+
7
+ def configuration
8
+ @configuration ||= Configuration.new
9
+ end
10
+
11
+ extend self
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :logger
16
+
17
+ def initialize
18
+ @logger = ::Logger.new $stderr
19
+ @logger.level = ::Logger::WARN
20
+ @logger.progname = "relaton-iso"
21
+ @logger.formatter = proc do |_severity, _datetime, progname, msg|
22
+ "[#{progname}] #{msg}\n"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -42,9 +42,9 @@ module RelatonIso
42
42
  # @return [Pubid::Iso::Identifier]
43
43
  def pubid
44
44
  @pubid ||= Pubid::Iso::Identifier.parse_from_title(hit[:title])
45
- rescue Pubid::Iso::Errors::WrongTypeError => e
46
- warn "[relaton-iso] unable to find an identifier in \"#{hit[:title]}\"."
47
- warn "[relaton-iso] #{e.message}"
45
+ rescue Pubid::Iso::Errors::WrongTypeError, Pubid::Iso::Errors::ParseError => e
46
+ Logger.warn "unable to find an identifier in \"#{hit[:title]}\"."
47
+ Logger.warn e.message
48
48
  end
49
49
  end
50
50
  end
@@ -6,17 +6,19 @@ require "relaton_iso/hit"
6
6
  module RelatonIso
7
7
  # Page of hit collection.
8
8
  class HitCollection < RelatonBib::HitCollection
9
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
9
+ # @return [Boolean] whether the search was performed on GitHub
10
+ attr_reader :from_gh
10
11
 
11
12
  # @param text [String] reference to search
12
13
  def initialize(text)
13
14
  super
14
- @array = text.match?(/^ISO[\s\/](?:TC\s184\/SC\s?4|IEC\sDIR\s(?:\d|IEC|JTC))/) ? fetch_github : fetch_iso
15
+ @from_gh = text.match?(/^ISO[\s\/](?:TC\s184\/SC\s?4|IEC\sDIR\s(?:\d|IEC|JTC))/)
16
+ @array = from_gh ? fetch_github : fetch_iso
15
17
  end
16
18
 
17
19
  # @param lang [String, NilClass]
18
20
  # @return [RelatonIsoBib::IsoBibliographicItem, nil]
19
- def to_all_parts(lang = nil) # rubocop:disable Metrics/CyclomaticComplexity
21
+ def to_all_parts(lang = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
20
22
  # parts = @array.reject { |h| h.hit["docPart"]&.empty? }
21
23
  hit = @array.min_by { |h| h.pubid.part.to_i }
22
24
  return @array.first&.fetch lang unless hit
@@ -33,7 +35,6 @@ module RelatonIso
33
35
  end
34
36
  all_parts_item
35
37
  end
36
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
37
38
 
38
39
  private
39
40
 
@@ -63,23 +64,11 @@ module RelatonIso
63
64
  # @return [Array<RelatonIso::Hit>]
64
65
  #
65
66
  def fetch_iso # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
66
- # %r{\s(?<num>\d+)(?:-(?<part>[\d-]+))?} =~ text
67
- # http = Net::HTTP.new "www.iso.org", 443
68
- # http.use_ssl = true
69
- # search = ["status=ENT_ACTIVE,ENT_PROGRESS,ENT_INACTIVE,ENT_DELETED"]
70
- # search << "docNumber=#{num}"
71
- # search << "docPartNo=#{part}" if part
72
- # q = search.join "&"
73
- # resp = http.get("/cms/render/live/en/sites/isoorg.advancedSearch.do?#{q}",
74
- # "Accept" => "application/json, text/plain, */*")
75
67
  config = Algolia::Search::Config.new(application_id: "JCL49WV5AR", api_key: "dd1b9e1ab383f4d4817d29cd5e96d3f0")
76
- client = Algolia::Search::Client.new config, logger: ::Logger.new($stderr)
68
+ client = Algolia::Search::Client.new config, logger: Config.configuration.logger
77
69
  index = client.init_index "all_en"
78
70
  resp = index.search text, hitsPerPage: 100, filters: "category:standard"
79
- # return [] if resp.body.empty?
80
71
 
81
- # json = JSON.parse resp.body
82
- # json["standards"]
83
72
  resp[:hits].map { |h| Hit.new h, self }.sort! do |a, b|
84
73
  if a.sort_weight == b.sort_weight && b.hit[:year] = a.hit[:year]
85
74
  a.hit[:title] <=> b.hit[:title]
@@ -90,19 +79,5 @@ module RelatonIso
90
79
  end
91
80
  end
92
81
  end
93
-
94
- # @param hit [Hash]
95
- # @return [Date]
96
- # def parse_date(hit)
97
- # if hit["publicationDate"]
98
- # Date.strptime(hit["publicationDate"], "%Y-%m")
99
- # elsif %r{:(?<year>\d{4})} =~ hit["docRef"]
100
- # Date.strptime(year, "%Y")
101
- # elsif hit["newProjectDate"]
102
- # Date.parse hit["newProjectDate"]
103
- # else
104
- # Date.new 0
105
- # end
106
- # end
107
82
  end
108
83
  end
@@ -12,7 +12,7 @@ module RelatonIso
12
12
  # @param text [String]
13
13
  # @return [RelatonIso::HitCollection]
14
14
  def search(text)
15
- HitCollection.new text.gsub(/\u2013/, "-")
15
+ HitCollection.new text.gsub("\u2013", "-")
16
16
  rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
17
17
  EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
18
18
  Net::ProtocolError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT,
@@ -29,7 +29,7 @@ module RelatonIso
29
29
  #
30
30
  # @return [RelatonIsoBib::IsoBibliographicItem] Relaton XML serialisation of reference
31
31
  def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/AbcSize
32
- code = ref.gsub(/\u2013/, "-")
32
+ code = ref.gsub("\u2013", "-")
33
33
 
34
34
  # parse "all parts" request
35
35
  code.sub! " (all parts)", ""
@@ -37,43 +37,24 @@ module RelatonIso
37
37
 
38
38
  query_pubid = Pubid::Iso::Identifier.parse(code)
39
39
  query_pubid.year = year if year
40
+ query_pubid.part = nil if opts[:all_parts]
41
+ Logger.warn "(\"#{query_pubid}\") Fetching from ISO..."
40
42
 
41
- resp = isobib_search_filter(query_pubid, opts)
42
-
43
- # Try with ISO/IEC prefix if ISO not found
44
- if resp[:hits].empty? && query_pubid.copublisher.nil? &&
45
- query_pubid.publisher == "ISO"
46
- resp_isoiec = retry_isoiec_prefix(query_pubid, opts)
47
- resp = resp_isoiec unless resp_isoiec.nil?
48
- end
43
+ hits, missed_year_ids = isobib_search_filter(query_pubid, opts)
44
+ tip_ids = look_up_with_any_types_stages(hits, query_pubid, opts)
49
45
 
50
- # return only first one if not all_parts
51
- ret = if !opts[:all_parts] || resp[:hits].size == 1
52
- resp[:hits].any? && resp[:hits].first.fetch(opts[:lang])
46
+ ret = if !opts[:all_parts] || hits.size == 1
47
+ hits.any? && hits.first.fetch(opts[:lang])
53
48
  else
54
- resp[:hits].to_all_parts(opts[:lang])
49
+ hits.to_all_parts(opts[:lang])
55
50
  end
56
51
 
57
- return fetch_ref_err(query_pubid) unless ret
52
+ return fetch_ref_err(query_pubid, missed_year_ids, tip_ids) unless ret
58
53
 
59
- # puts "xxxxx #{ret.docidentifier.first.id.inspect}"
60
54
  response_docid = ret.docidentifier.first.id.sub(" (all parts)", "")
61
55
  response_pubid = Pubid::Iso::Identifier.parse(response_docid)
62
- # puts "xxxxx query_pubid(#{query_pubid}) response_pubid(#{response_pubid})"
63
-
64
- if query_pubid.to_s == response_pubid.to_s
65
- warn "[relaton-iso] (\"#{query_pubid}\") Found exact match."
66
- elsif matches_base?(query_pubid, response_pubid)
67
- warn "[relaton-iso] (\"#{query_pubid}\") " \
68
- "Found (\"#{response_pubid}\")."
69
- elsif matches_base?(query_pubid, response_pubid, any_types_stages: true)
70
- warn "[relaton-iso] (\"#{query_pubid}\") TIP: " \
71
- "Found with different type/stage, " \
72
- "please amend to (\"#{response_pubid}\")."
73
- else
74
- # when there are all parts
75
- warn "[relaton-iso] (\"#{query_pubid}\") Found (\"#{response_pubid}\")."
76
- end
56
+
57
+ Logger.warn "(\"#{query_pubid}\") Found (\"#{response_pubid}\")."
77
58
 
78
59
  get_all = (
79
60
  (query_pubid.year && opts[:keep_year].nil?) ||
@@ -83,9 +64,9 @@ module RelatonIso
83
64
  return ret if get_all
84
65
 
85
66
  ret.to_most_recent_reference
86
-
87
67
  rescue Pubid::Core::Errors::ParseError
88
- warn "[relaton-iso] (\"#{code}\") is not recognized as a standards identifier."
68
+ Logger.warn "(\"#{code}\") is not recognized as a standards identifier."
69
+ nil
89
70
  end
90
71
 
91
72
  # @param query_pubid [Pubid::Iso::Identifier]
@@ -109,147 +90,111 @@ module RelatonIso
109
90
  # @return [<Type>] <description>
110
91
  #
111
92
  def matches_base?(query_pubid, pubid, any_types_stages: false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics?PerceivedComplexity
112
- return unless pubid.respond_to?(:publisher)
93
+ return false unless pubid.respond_to?(:publisher)
113
94
 
114
95
  query_pubid.publisher == pubid.publisher &&
115
96
  query_pubid.number == pubid.number &&
116
97
  query_pubid.copublisher == pubid.copublisher &&
117
- ((any_types_stages && query_pubid.stage.nil?) || query_pubid.stage == pubid.stage) &&
118
- ((any_types_stages && query_pubid.type.nil?) || query_pubid.type == pubid.type)
98
+ (any_types_stages || query_pubid.stage == pubid.stage) &&
99
+ (any_types_stages || query_pubid.is_a?(pubid.class))
119
100
  end
120
101
 
121
102
  # @param hit_collection [RelatonIso::HitCollection]
122
103
  # @param year [String]
123
- # @return [RelatonIso::HitCollection]
124
- def filter_hits_by_year(hit_collection, year) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
125
- missed_years = []
126
- return { hits: hit_collection, missed_years: missed_years } if year.nil?
104
+ # @return [Array<RelatonIso::HitCollection, Array<String>>] hits and missed year IDs
105
+ def filter_hits_by_year(hit_collection, year)
106
+ missed_year_ids = Set.new
107
+ return [hit_collection, missed_year_ids] if year.nil?
127
108
 
128
109
  # filter by year
129
110
  hits = hit_collection.select do |hit|
130
- if (hit.pubid.base.nil? && hit.pubid.year.to_s == year.to_s) ||
131
- (!hit.pubid.base.nil? && hit.pubid.base.year.to_s == year.to_s) ||
132
- (!hit.pubid.base.nil? && hit.pubid.year.to_s == year.to_s)
133
- true
134
- elsif hit.pubid.year.nil? && hit.hit[:year].to_s == year
135
- hit.pubid.year = year
136
- true
137
- else
138
- missed_year = (hit.pubid.year || hit.hit[:year]).to_s
139
- if missed_year && !missed_year.empty? && !missed_years.include?(missed_year)
140
- missed_years << missed_year
141
- end
142
- false
143
- end
111
+ hit.pubid.year ||= hit.hit[:year]
112
+ next true if check_year(year, hit)
113
+
114
+ missed_year_ids << hit.pubid.to_s if hit.pubid.year
115
+ false
144
116
  end
145
117
 
146
- { hits: hits, missed_years: missed_years }
118
+ [hits, missed_year_ids]
147
119
  end
148
120
 
149
121
  private
150
122
 
151
- # @param query_pubid [Pubid::Iso::Identifier] PubID with no results
152
- def fetch_ref_err(query_pubid) # rubocop:disable Metrics/MethodLength
153
- warn "[relaton-iso] (\"#{query_pubid}\") " \
154
- "Not found. " \
155
- "The identifier must be exactly as shown on the ISO website."
123
+ def check_year(year, hit) # rubocop:disable Metrics/AbcSize
124
+ (hit.pubid.base.nil? && hit.pubid.year.to_s == year.to_s) ||
125
+ (!hit.pubid.base.nil? && hit.pubid.base.year.to_s == year.to_s) ||
126
+ (!hit.pubid.base.nil? && hit.pubid.year.to_s == year.to_s)
127
+ end
156
128
 
157
- if query_pubid.part
158
- warn "[relaton-iso] (\"#{query_pubid}\") TIP: " \
159
- "If it cannot be found, the document may no longer be published in parts."
160
- else
161
- warn "[relaton-iso] (\"#{query_pubid}\") TIP: " \
162
- "If you wish to cite all document parts for the reference, " \
163
- "use (\"#{query_pubid.to_s(format: :ref_undated)} (all parts)\")."
129
+ # @param pubid [Pubid::Iso::Identifier] PubID with no results
130
+ def fetch_ref_err(pubid, missed_year_ids, tip_ids) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
131
+ Logger.warn "(\"#{pubid}\") Not found."
132
+
133
+ if missed_year_ids.any?
134
+ ids = missed_year_ids.map { |i| "\"#{i}\"" }.join(", ")
135
+ Logger.warn "(\"#{pubid}\") TIP: No match for edition year " \
136
+ "#{pubid.year}, but matches exist for #{ids}."
164
137
  end
165
138
 
166
- unless %w(TS TR PAS Guide).include?(query_pubid.type)
167
- warn "[relaton-iso] (\"#{query_pubid}\") TIP: " \
168
- "If the document is not an International Standard, use its " \
169
- "deliverable type abbreviation (TS, TR, PAS, Guide)."
139
+ if tip_ids.any?
140
+ ids = tip_ids.map { |i| "\"#{i}\"" }.join(", ")
141
+ Logger.warn "(\"#{pubid}\") TIP: Matches exist for #{ids}."
170
142
  end
171
143
 
172
- nil
173
- end
144
+ if pubid.part
145
+ Logger.warn "(\"#{pubid}\") TIP: If it cannot be found, " \
146
+ "the document may no longer be published in parts."
147
+ else
148
+ Logger.warn "(\"#{pubid}\") TIP: If you wish to cite " \
149
+ "all document parts for the reference, use " \
150
+ "(\"#{pubid.to_s(format: :ref_undated)} (all parts)\")."
151
+ end
174
152
 
175
- # @param pubid [Pubid::Iso::Identifier]
176
- # @param missed_years [Array<String>]
177
- def warn_missing_years(pubid, missed_years)
178
- warn "[relaton-iso] (\"#{pubid}\") TIP: " \
179
- "No match for edition year #{pubid.year}, " \
180
- "but matches exist for #{missed_years.uniq.join(', ')}."
153
+ nil
181
154
  end
182
155
 
183
- # Search for hits using ISO/IEC prefix.
184
- #
185
- # @param old_pubid [Pubid::Iso::Identifier] reference with ISO prefix
186
- # @param opts [Hash]
187
- # @return [Array<RelatonIso::Hit>]
188
- def retry_isoiec_prefix(old_pubid, opts) # rubocop:disable Metrics/MethodLength
189
- return nil unless old_pubid.copublisher.nil? && old_pubid.publisher == "ISO"
190
-
191
- pubid = old_pubid.dup
192
- pubid.copublisher = "IEC"
193
- warn "[relaton-iso] (\"#{old_pubid}\") Not found, trying with ISO/IEC prefix (\"#{pubid}\")..."
194
- resp_isoiec = isobib_search_filter(pubid, opts)
195
-
196
- if resp_isoiec[:hits].empty?
197
- warn "[relaton-iso] (\"#{pubid}\") Not found. "
198
- return nil
199
- end
200
-
201
- warn "[relaton-iso] (\"#{pubid}\") TIP: Found with ISO/IEC prefix, " \
202
- "please amend to (\"#{pubid}\")."
156
+ def look_up_with_any_types_stages(hits, pubid, opts) # rubocop:disable Metrics/MethodLength
157
+ found_ids = []
158
+ return found_ids unless !hits.from_gh && hits.empty? && pubid.copublisher.nil?
203
159
 
204
- resp_isoiec
160
+ resp, = isobib_search_filter(pubid, opts, any_types_stages: true)
161
+ resp.map &:pubid
205
162
  end
206
163
 
164
+ #
207
165
  # Search for hits. If no found then trying missed stages.
208
166
  #
209
167
  # @param query_pubid [Pubid::Iso::Identifier] reference without correction
210
168
  # @param opts [Hash]
211
- # @return [Array<RelatonIso::Hit>]
212
- def isobib_search_filter(query_pubid, opts) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
213
- missed_years = []
214
- query_pubid.part = nil if opts[:all_parts]
215
- warn "[relaton-iso] (\"#{query_pubid}\") Fetching from ISO..."
216
-
217
- # fetch hits collection
169
+ # @param any_types_stages [Boolean] match with any stages
170
+ #
171
+ # @return [Array<RelatonIso::HitCollection, Array<String>>] hits and missed years
172
+ #
173
+ def isobib_search_filter(query_pubid, opts, any_types_stages: false) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
218
174
  query_pubid_without_year = query_pubid.dup
219
175
  # remove year for query
220
176
  query_pubid_without_year.year = nil
221
177
  hit_collection = search(query_pubid_without_year.to_s)
222
178
 
223
179
  # filter only matching hits
224
- res = filter_hits hit_collection, query_pubid, all_parts: opts[:all_parts]
225
- return res unless res[:hits].empty?
226
-
227
- missed_years += res[:missed_years]
228
-
229
- # lookup for documents with stages when no match without stage
230
- res = filter_hits hit_collection, query_pubid,
231
- all_parts: opts[:all_parts], any_types_stages: true
232
- return res unless res[:hits].empty?
233
-
234
- missed_years += res[:missed_years]
235
-
236
- if missed_years.any?
237
- warn_missing_years(query_pubid, missed_years)
238
- end
239
-
240
- res
180
+ filter_hits hit_collection, query_pubid, opts[:all_parts], any_types_stages
241
181
  end
242
182
 
243
- # @param hits [RelatonIso::HitCollection]
183
+ #
184
+ # Filter hits by query_pubid.
185
+ #
186
+ # @param hit_collection [RelatonIso::HitCollection]
244
187
  # @param query_pubid [Pubid::Iso::Identifier]
245
188
  # @param all_parts [Boolean]
246
- # @param any_stages [Boolean]
247
- # @return [RelatonIso::HitCollection]
248
- def filter_hits(hit_collection, query_pubid, all_parts: false, any_types_stages: false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
189
+ # @param any_stypes_tages [Boolean]
190
+ #
191
+ # @return [Array<RelatonIso::HitCollection, Array<String>>] hits and missed year IDs
192
+ #
193
+ def filter_hits(hit_collection, query_pubid, all_parts, any_stypes_tages) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
249
194
  # filter out
250
195
  result = hit_collection.select do |i|
251
196
  hit_pubid = i.pubid
252
- matches_base?(query_pubid, hit_pubid, any_types_stages: any_types_stages) &&
197
+ matches_base?(query_pubid, hit_pubid, any_types_stages: any_stypes_tages) &&
253
198
  matches_parts?(query_pubid, hit_pubid, all_parts: all_parts) &&
254
199
  query_pubid.corrigendums == hit_pubid.corrigendums &&
255
200
  query_pubid.amendments == hit_pubid.amendments
@@ -0,0 +1,13 @@
1
+ module RelatonIso
2
+ module Logger
3
+ extend self
4
+
5
+ def method_missing(method, *args, &block)
6
+ Config.configuration.logger.send(method, *args, &block)
7
+ end
8
+
9
+ def respond_to_missing?(method_name, include_private = false)
10
+ Config.configuration.logger.respond_to?(method_name) || super
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonIso
4
- VERSION = "1.15.4"
4
+ VERSION = "1.15.5"
5
5
  end
data/lib/relaton_iso.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "logger"
4
+ require "pubid-iso"
5
+ require "relaton_iso/config"
6
+ require "relaton_iso/logger"
3
7
  require "relaton_iso/version"
4
8
  require "relaton_iso/iso_bibliography"
5
- require "pubid-iso"
6
9
  require "relaton_iso/document_identifier"
data/relaton_iso.gemspec CHANGED
@@ -10,10 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ["Ribose Inc."]
11
11
  spec.email = ["open.source@ribose.com"]
12
12
 
13
- spec.summary = "RelatonIso: retrieve ISO Standards for bibliographic use "\
14
- "using the IsoBibliographicItem model"
15
- spec.description = "RelatonIso: retrieve ISO Standards for bibliographic use "\
16
- "using the IsoBibliographicItem model"
13
+ spec.summary = "RelatonIso: retrieve ISO Standards for bibliographic " \
14
+ "use using the IsoBibliographicItem model"
15
+ spec.description = "RelatonIso: retrieve ISO Standards for bibliographic " \
16
+ "use using the IsoBibliographicItem model"
17
17
 
18
18
  spec.homepage = "https://github.com/relaton/relaton-iso"
19
19
  spec.license = "BSD-2-Clause"
@@ -26,11 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
28
28
 
29
- spec.add_development_dependency "equivalent-xml", "~> 0.6"
30
- spec.add_development_dependency "rake", "~> 13.0"
31
- spec.add_development_dependency "rspec", "~> 3.0"
32
-
33
29
  spec.add_dependency "algolia", "~> 2.3.0"
30
+ spec.add_dependency "pubid-core", "1.8.5"
34
31
  spec.add_dependency "pubid-iso", "~> 0.5.0"
32
+ spec.add_dependency "relaton-bib", "~> 1.14.12"
35
33
  spec.add_dependency "relaton-iso-bib", "~> 1.14.0"
36
34
  end
metadata CHANGED
@@ -1,85 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.4
4
+ version: 1.15.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-18 00:00:00.000000000 Z
11
+ date: 2023-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: equivalent-xml
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.6'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.6'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
14
+ name: algolia
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '13.0'
34
- type: :development
19
+ version: 2.3.0
20
+ type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '13.0'
26
+ version: 2.3.0
41
27
  - !ruby/object:Gem::Dependency
42
- name: rspec
28
+ name: pubid-core
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - "~>"
31
+ - - '='
46
32
  - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
33
+ version: 1.8.5
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - '='
53
39
  - !ruby/object:Gem::Version
54
- version: '3.0'
40
+ version: 1.8.5
55
41
  - !ruby/object:Gem::Dependency
56
- name: algolia
42
+ name: pubid-iso
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 2.3.0
47
+ version: 0.5.0
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 2.3.0
54
+ version: 0.5.0
69
55
  - !ruby/object:Gem::Dependency
70
- name: pubid-iso
56
+ name: relaton-bib
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: 0.5.0
61
+ version: 1.14.12
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: 0.5.0
68
+ version: 1.14.12
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: relaton-iso-bib
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -135,10 +121,12 @@ files:
135
121
  - bin/setup
136
122
  - bin/thor
137
123
  - lib/relaton_iso.rb
124
+ - lib/relaton_iso/config.rb
138
125
  - lib/relaton_iso/document_identifier.rb
139
126
  - lib/relaton_iso/hit.rb
140
127
  - lib/relaton_iso/hit_collection.rb
141
128
  - lib/relaton_iso/iso_bibliography.rb
129
+ - lib/relaton_iso/logger.rb
142
130
  - lib/relaton_iso/processor.rb
143
131
  - lib/relaton_iso/scrapper.rb
144
132
  - lib/relaton_iso/version.rb
@@ -147,7 +135,7 @@ homepage: https://github.com/relaton/relaton-iso
147
135
  licenses:
148
136
  - BSD-2-Clause
149
137
  metadata: {}
150
- post_install_message:
138
+ post_install_message:
151
139
  rdoc_options: []
152
140
  require_paths:
153
141
  - lib
@@ -162,8 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
150
  - !ruby/object:Gem::Version
163
151
  version: '0'
164
152
  requirements: []
165
- rubygems_version: 3.4.9
166
- signing_key:
153
+ rubygems_version: 3.3.26
154
+ signing_key:
167
155
  specification_version: 4
168
156
  summary: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
169
157
  model'