relaton-iso 1.15.5 → 1.15.6

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: d8f96ec7677b17a7e89ca54cc7230eda13391749c404fcc8d95bca32ddb61d98
4
- data.tar.gz: c74831929f8d4d276e1aae6c06990559e51bcc4ba1ea3c627fef33d141463612
3
+ metadata.gz: fadb60d3f225174438b872a27c8632fcb9dcb685b66ef67071b7ab16dd78f052
4
+ data.tar.gz: b53c685d0adf0856851f31d1808654f59f16d0ccd8db70b2ef818b22126e505e
5
5
  SHA512:
6
- metadata.gz: 80862ee504de862925e70c188ae40ed13001748f87f9af41aaad00e1e3e2b473779da64e0402ac920ac84af6318e19fe8ec6d73c7d6ff5b752b20f3fd0d2721c
7
- data.tar.gz: e896e1986545b722df2393b075ce947d2ab00ca365249498b4a0e738ebcb9669475e72961e2ab90495181ce8ccd5af8df380d697b9433b335e013ab554ddf23a
6
+ metadata.gz: a10856c01099b1590b99ab0c2102aaf6dee654bd3fdf0b6a7f0717d3f85881bc58999219168e6ba707846cbd3fc785fbc9951003d7c21ad6c134af2a0fb0d4ea
7
+ data.tar.gz: a9a4b7a79acf34a0a42218f28979ec06a41c0b6305fcfbb77ebec0cf4881e2b806548ae5603112122420f1c4ed0d365d9be50a2c291fb4d5a00fe68534f2311b
@@ -7,7 +7,8 @@ on:
7
7
  inputs:
8
8
  next_version:
9
9
  description: |
10
- Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
10
+ Next release version. Possible values: x.y.z, major, minor, patch (or pre|rc|etc).
11
+ Also, you can pass 'skip' to skip 'git tag' and do 'gem push' for the current version
11
12
  required: true
12
13
  default: 'skip'
13
14
  repository_dispatch:
data/README.adoc CHANGED
@@ -31,13 +31,24 @@ Or install it yourself as:
31
31
 
32
32
  == Usage
33
33
 
34
- === Search for standards using keywords
34
+ === Configuration
35
+
36
+ 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 `RelatonIso.configure` block.
35
37
 
36
38
  [source,ruby]
37
39
  ----
38
40
  require 'relaton_iso'
39
41
  => true
40
42
 
43
+ RelatonIso.configure do |config|
44
+ config.logger.level = Logger::DEBUG
45
+ end
46
+ ----
47
+
48
+ === Search for standards using keywords
49
+
50
+ [source,ruby]
51
+ ----
41
52
  hit_collection = RelatonIso::IsoBibliography.search("ISO 19115")
42
53
  => <RelatonIso::HitCollection:0x007fa5bc847038 @ref=19115 @fetched=false>
43
54
 
@@ -1,26 +1,10 @@
1
1
  module RelatonIso
2
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
3
+ include RelatonBib::Config
12
4
  end
5
+ extend Config
13
6
 
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
7
+ class Configuration < RelatonBib::Configuration
8
+ PROGNAME = "relaton-iso".freeze
25
9
  end
26
10
  end
@@ -43,8 +43,8 @@ module RelatonIso
43
43
  def pubid
44
44
  @pubid ||= Pubid::Iso::Identifier.parse_from_title(hit[:title])
45
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
46
+ Util.warn "unable to find an identifier in `#{hit[:title]}`."
47
+ Util.warn e.message
48
48
  end
49
49
  end
50
50
  end
@@ -13,7 +13,11 @@ module RelatonIso
13
13
  def initialize(text)
14
14
  super
15
15
  @from_gh = text.match?(/^ISO[\s\/](?:TC\s184\/SC\s?4|IEC\sDIR\s(?:\d|IEC|JTC))/)
16
+ end
17
+
18
+ def fetch
16
19
  @array = from_gh ? fetch_github : fetch_iso
20
+ self
17
21
  end
18
22
 
19
23
  # @param lang [String, NilClass]
@@ -65,7 +69,7 @@ module RelatonIso
65
69
  #
66
70
  def fetch_iso # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
67
71
  config = Algolia::Search::Config.new(application_id: "JCL49WV5AR", api_key: "dd1b9e1ab383f4d4817d29cd5e96d3f0")
68
- client = Algolia::Search::Client.new config, logger: Config.configuration.logger
72
+ client = Algolia::Search::Client.new config, logger: RelatonIso.configuration.logger
69
73
  index = client.init_index "all_en"
70
74
  resp = index.search text, hitsPerPage: 100, filters: "category:standard"
71
75
 
@@ -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", "-")).fetch
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,
@@ -38,10 +38,10 @@ module RelatonIso
38
38
  query_pubid = Pubid::Iso::Identifier.parse(code)
39
39
  query_pubid.year = year if year
40
40
  query_pubid.part = nil if opts[:all_parts]
41
- Logger.warn "(\"#{query_pubid}\") Fetching from ISO..."
41
+ Util.warn "(#{query_pubid}) Fetching from ISO..."
42
42
 
43
43
  hits, missed_year_ids = isobib_search_filter(query_pubid, opts)
44
- tip_ids = look_up_with_any_types_stages(hits, query_pubid, opts)
44
+ tip_ids = look_up_with_any_types_stages(hits, ref, opts)
45
45
 
46
46
  ret = if !opts[:all_parts] || hits.size == 1
47
47
  hits.any? && hits.first.fetch(opts[:lang])
@@ -54,7 +54,7 @@ module RelatonIso
54
54
  response_docid = ret.docidentifier.first.id.sub(" (all parts)", "")
55
55
  response_pubid = Pubid::Iso::Identifier.parse(response_docid)
56
56
 
57
- Logger.warn "(\"#{query_pubid}\") Found (\"#{response_pubid}\")."
57
+ Util.warn "(#{query_pubid}) Found `#{response_pubid}`."
58
58
 
59
59
  get_all = (
60
60
  (query_pubid.year && opts[:keep_year].nil?) ||
@@ -65,7 +65,7 @@ module RelatonIso
65
65
 
66
66
  ret.to_most_recent_reference
67
67
  rescue Pubid::Core::Errors::ParseError
68
- Logger.warn "(\"#{code}\") is not recognized as a standards identifier."
68
+ Util.warn "(#{code}) is not recognized as a standards identifier."
69
69
  nil
70
70
  end
71
71
 
@@ -128,35 +128,37 @@ module RelatonIso
128
128
 
129
129
  # @param pubid [Pubid::Iso::Identifier] PubID with no results
130
130
  def fetch_ref_err(pubid, missed_year_ids, tip_ids) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
131
- Logger.warn "(\"#{pubid}\") Not found."
131
+ Util.warn "(#{pubid}) Not found."
132
132
 
133
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}."
134
+ ids = missed_year_ids.map { |i| "`#{i}`" }.join(", ")
135
+ Util.warn "(#{pubid}) TIP: No match for edition year " \
136
+ "#{pubid.year}, but matches exist for #{ids}."
137
137
  end
138
138
 
139
139
  if tip_ids.any?
140
- ids = tip_ids.map { |i| "\"#{i}\"" }.join(", ")
141
- Logger.warn "(\"#{pubid}\") TIP: Matches exist for #{ids}."
140
+ ids = tip_ids.map { |i| "`#{i}`" }.join(", ")
141
+ Util.warn "(#{pubid}) TIP: Matches exist for #{ids}."
142
142
  end
143
143
 
144
144
  if pubid.part
145
- Logger.warn "(\"#{pubid}\") TIP: If it cannot be found, " \
146
- "the document may no longer be published in parts."
145
+ Util.warn "(#{pubid}) TIP: If it cannot be found, " \
146
+ "the document may no longer be published in parts."
147
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)\")."
148
+ Util.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
151
  end
152
152
 
153
153
  nil
154
154
  end
155
155
 
156
- def look_up_with_any_types_stages(hits, pubid, opts) # rubocop:disable Metrics/MethodLength
156
+ def look_up_with_any_types_stages(hits, ref, opts) # rubocop:disable Metrics/MethodLength
157
157
  found_ids = []
158
- return found_ids unless !hits.from_gh && hits.empty? && pubid.copublisher.nil?
158
+ return found_ids if hits.from_gh || hits.any? || !ref.match?(/^ISO[\/\s][A-Z]/)
159
159
 
160
+ ref_no_type_stage = ref.sub(/^ISO[\/\s][A-Z]+/, "ISO")
161
+ pubid = Pubid::Iso::Identifier.parse(ref_no_type_stage)
160
162
  resp, = isobib_search_filter(pubid, opts, any_types_stages: true)
161
163
  resp.map &:pubid
162
164
  end
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "relaton_iso_bib"
4
- require "relaton_iso/hit"
5
- require "nokogiri"
6
- require "net/http"
7
-
8
3
  module RelatonIso
9
4
  # Scrapper.
10
5
  module Scrapper # rubocop:disable Metrics/ModuleLength
@@ -0,0 +1,9 @@
1
+ module RelatonIso
2
+ module Util
3
+ extend RelatonBib::Util
4
+
5
+ def self.logger
6
+ RelatonIso.configuration.logger
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonIso
4
- VERSION = "1.15.5"
4
+ VERSION = "1.15.6"
5
5
  end
data/lib/relaton_iso.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "nokogiri"
4
+ require "net/http"
3
5
  require "logger"
4
6
  require "pubid-iso"
5
- require "relaton_iso/config"
6
- require "relaton_iso/logger"
7
+ require "relaton_iso_bib"
7
8
  require "relaton_iso/version"
9
+ require "relaton_iso/config"
10
+ require "relaton_iso/util"
11
+ require "relaton_iso/hit"
8
12
  require "relaton_iso/iso_bibliography"
9
13
  require "relaton_iso/document_identifier"
data/relaton_iso.gemspec CHANGED
@@ -27,8 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
28
28
 
29
29
  spec.add_dependency "algolia", "~> 2.3.0"
30
- spec.add_dependency "pubid-core", "1.8.5"
31
- spec.add_dependency "pubid-iso", "~> 0.5.0"
32
- spec.add_dependency "relaton-bib", "~> 1.14.12"
30
+ spec.add_dependency "pubid-iso", "~> 0.6.0"
31
+ spec.add_dependency "relaton-bib", "~> 1.14.13"
33
32
  spec.add_dependency "relaton-iso-bib", "~> 1.14.0"
34
33
  end
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.15.5
4
+ version: 1.15.6
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-08-03 00:00:00.000000000 Z
11
+ date: 2023-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: algolia
@@ -24,48 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.3.0
27
- - !ruby/object:Gem::Dependency
28
- name: pubid-core
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 1.8.5
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 1.8.5
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: pubid-iso
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: 0.5.0
33
+ version: 0.6.0
48
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: 0.5.0
40
+ version: 0.6.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: relaton-bib
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 1.14.12
47
+ version: 1.14.13
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: 1.14.12
54
+ version: 1.14.13
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: relaton-iso-bib
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -126,9 +112,9 @@ files:
126
112
  - lib/relaton_iso/hit.rb
127
113
  - lib/relaton_iso/hit_collection.rb
128
114
  - lib/relaton_iso/iso_bibliography.rb
129
- - lib/relaton_iso/logger.rb
130
115
  - lib/relaton_iso/processor.rb
131
116
  - lib/relaton_iso/scrapper.rb
117
+ - lib/relaton_iso/util.rb
132
118
  - lib/relaton_iso/version.rb
133
119
  - relaton_iso.gemspec
134
120
  homepage: https://github.com/relaton/relaton-iso
@@ -1,13 +0,0 @@
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