relaton-bsi 1.16.0 → 1.16.2

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: 02a7a2396cd1217d1136a7a9b386faa0e68dc323c2b575432135eaceb82d5a49
4
- data.tar.gz: 78d05d994d33be9bfaf38563fdbac05a394d49a9bd6e52a0e331935e1d821087
3
+ metadata.gz: beee0d1d60affb54c0d473077b8b792271bd773a89462aa9668794a47c8c37b4
4
+ data.tar.gz: 3f4a940e53481c52b6ff1d155a0ae1e9cccdc20a768753d59efb042beed7a80b
5
5
  SHA512:
6
- metadata.gz: 1a8472d369486ba81fc493a275d8b14df1aff5a398441b31adbec582a9f9b989f14c9b325e0fb5e7004361481e7f3103d07d766d1945255a1b1de7a92d61c565
7
- data.tar.gz: 83cdb931c8c3de6496e03ff95797e075683c20b9bb97ac6a230b9fdae82f2d7c1d5709a3572932e6f03e56955dacc905b904d4e01b2d29c66aa0494fe2c677a4
6
+ metadata.gz: d890a38ea4d5ba876d4e6e8497347e45bb3067aca5796f8c574a8d7de9e337836655158d9f3ce1ed1d1687c923750ee570b80994ea238be9e32df156bc6fd808
7
+ data.tar.gz: c12c4a02bd22a07cd63378de4a2a701df11e119e12717e8e28d74b7c6ce453712c123b8b55a10675f3b78e7bce23aebbc0187bb79ef5366e43aab0de46e7e3a5
data/README.adoc CHANGED
@@ -27,13 +27,24 @@ Or install it yourself as:
27
27
 
28
28
  == Usage
29
29
 
30
- === Search for a standard using keywords
30
+ === Configuration
31
+
32
+ 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 `RelatonBsi.configure` block.
31
33
 
32
34
  [source,ruby]
33
35
  ----
34
36
  require 'relaton_bsi'
35
37
  => true
36
38
 
39
+ RelatonBsi.configure do |config|
40
+ config.logger.level = Logger::DEBUG
41
+ end
42
+ ----
43
+
44
+ === Search for a standard using keywords
45
+
46
+ [source,ruby]
47
+ ----
37
48
  hit_collection = RelatonBsi::BsiBibliography.search("BS EN ISO 8848")
38
49
  => <RelatonBsi::HitCollection:0x007fead49fe1f8 @ref=BS EN ISO 8848 @fetched=false>
39
50
 
@@ -89,14 +100,14 @@ item.to_xml bibdata: true
89
100
  [source,ruby]
90
101
  ----
91
102
  RelatonBsi::BsiBibliography.get "BS EN ISO 8848:2021"
92
- [relaton-bsi] ("BS EN ISO 8848:2021") fetching...
93
- [relaton-bsi] ("BS EN ISO 8848:2021") found BS EN ISO 8848:2021
103
+ [relaton-bsi] (BS EN ISO 8848:2021) Fetching from shop.bsigroup.com ...
104
+ [relaton-bsi] (BS EN ISO 8848:2021) Found: `BS EN ISO 8848:2021`
94
105
  => #<RelatonBsi::BsiBibliographicItem:0x007feb14814ca8
95
106
  ...
96
107
 
97
108
  RelatonBsi::BsiBibliography.get "BS EN ISO 8848", "2021"
98
- [relaton-bsi] ("BS EN ISO 8848") fetching...
99
- [relaton-bsi] ("BS EN ISO 8848") found BS EN ISO 8848:2021
109
+ [relaton-bsi] (BS EN ISO 8848) Fetching from shop.bsigroup.com ...
110
+ [relaton-bsi] (BS EN ISO 8848) Found: `BS EN ISO 8848:2021`
100
111
  => #<RelatonBsi::BsiBibliographicItem:0x007feaf59188a8
101
112
  ...
102
113
  ----
@@ -11,8 +11,8 @@ module RelatonBsi
11
11
 
12
12
  def initialize(**args) # rubocop:disable Metrics/AbcSize
13
13
  if args[:subdoctype] && !SUBDOCTYPES.include?(args[:subdoctype])
14
- warn "[relaton-bsi] WARNING: invalid subdoctype: #{args[:subdoctype]}"
15
- warn "[relaton-bsi] Allowed subdoctypes are: #{SUBDOCTYPES.join(', ')}"
14
+ Util.warn "WARNING: invalid subdoctype: `#{args[:subdoctype]}`"
15
+ Util.warn "Allowed subdoctypes are: `#{SUBDOCTYPES.join('`, `')}`"
16
16
  end
17
17
  super
18
18
  end
@@ -1,14 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # require "mechanize"
4
- require "relaton_iso_bib"
5
- require "relaton_bsi/bsi_bibliographic_item"
6
- require "relaton_bsi/scrapper"
7
- require "relaton_bsi/hit_collection"
8
- require "relaton_bsi/hit"
9
- require "relaton_bsi/xml_parser"
10
- require "relaton_bsi/hash_converter"
11
-
12
3
  module RelatonBsi
13
4
  # Class methods for search ISO standards.
14
5
  class BsiBibliography
@@ -64,11 +55,11 @@ module RelatonBsi
64
55
  def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
65
56
  y = code_parts(code)[:year]
66
57
  id = year && !y ? "#{code}:#{year}" : code
67
- warn "[relaton-bsi] WARNING: no match found online for #{id}. "\
68
- "The code must be exactly like it is on the standards website."
58
+ Util.warn "WARNING: no match found online for `#{id}`. " \
59
+ "The code must be exactly like it is on the standards website."
69
60
  unless missed_years.empty?
70
- warn "[relaton-bsi] (There was no match for #{year}, though there "\
71
- "were matches found for #{missed_years.join(', ')}.)"
61
+ Util.warn "There was no match for `#{year}`, though there " \
62
+ "were matches found for `#{missed_years.join('`, `')}`."
72
63
  end
73
64
  # if /\d-\d/.match? code
74
65
  # warn "[relaton-bsi] The provided document part may not exist, or "\
@@ -91,8 +82,11 @@ module RelatonBsi
91
82
  #
92
83
  def search_filter(code)
93
84
  cp = code_parts code
94
- warn "[relaton-bsi] (\"#{code}\") fetching..."
95
- return [] unless cp
85
+ Util.warn "(#{code}) Fetching from shop.bsigroup.com ..."
86
+ unless cp
87
+ Util.warn "(#{code}) Could not parse the reference"
88
+ return []
89
+ end
96
90
 
97
91
  search(code).filter_hits!(cp)
98
92
  end
@@ -121,9 +115,10 @@ module RelatonBsi
121
115
  result = search_filter(code) || return
122
116
  ret = results_filter(result, year)
123
117
  if ret[:ret]
124
- warn "[relaton-bsi] (\"#{code}\") found #{ret[:ret].docidentifier.first&.id}"
118
+ Util.warn "(#{code}) Found: `#{ret[:ret].docidentifier.first&.id}`"
125
119
  ret[:ret]
126
120
  else
121
+ Util.warn "(#{code}) No found"
127
122
  fetch_ref_err(code, year, ret[:years])
128
123
  end
129
124
  end
@@ -0,0 +1,10 @@
1
+ module RelatonBsi
2
+ module Config
3
+ include RelatonBib::Config
4
+ end
5
+ extend Config
6
+
7
+ class Configuration < RelatonBib::Configuration
8
+ PROGNAME = "relaton-bsi".freeze
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module RelatonBsi
2
+ module Util
3
+ extend RelatonBib::Util
4
+
5
+ def self.logger
6
+ RelatonBsi.configuration.logger
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonBsi
4
- VERSION = "1.16.0"
4
+ VERSION = "1.16.2"
5
5
  end
data/lib/relaton_bsi.rb CHANGED
@@ -1,15 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "relaton_iso_bib"
3
4
  require_relative "relaton_bsi/version"
5
+ require "relaton_bsi/config"
6
+ require "relaton_bsi/util"
4
7
  require "relaton_bsi/bsi_bibliography"
8
+ require "relaton_bsi/bsi_bibliographic_item"
9
+ require "relaton_bsi/scrapper"
10
+ require "relaton_bsi/hit_collection"
11
+ require "relaton_bsi/hit"
12
+ require "relaton_bsi/xml_parser"
13
+ require "relaton_bsi/hash_converter"
5
14
 
6
15
  module RelatonBsi
7
16
  # Returns hash of XML greammar
8
17
  # @return [String]
9
18
  def self.grammar_hash
10
- gem_path = File.expand_path "..", __dir__
11
- grammars_path = File.join gem_path, "grammars", "*"
12
- grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
13
- Digest::MD5.hexdigest grammars
19
+ # gem_path = File.expand_path "..", __dir__
20
+ # grammars_path = File.join gem_path, "grammars", "*"
21
+ # grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
22
+ Digest::MD5.hexdigest RelatonBsi::VERSION + RelatonIsoBib::VERSION + RelatonBib::VERSION # grammars
14
23
  end
15
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bsi
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-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: algolia
@@ -94,12 +94,14 @@ files:
94
94
  - lib/relaton_bsi.rb
95
95
  - lib/relaton_bsi/bsi_bibliographic_item.rb
96
96
  - lib/relaton_bsi/bsi_bibliography.rb
97
+ - lib/relaton_bsi/config.rb
97
98
  - lib/relaton_bsi/hash_converter.rb
98
99
  - lib/relaton_bsi/hit.rb
99
100
  - lib/relaton_bsi/hit_collection.rb
100
101
  - lib/relaton_bsi/processor.rb
101
102
  - lib/relaton_bsi/schema.json
102
103
  - lib/relaton_bsi/scrapper.rb
104
+ - lib/relaton_bsi/util.rb
103
105
  - lib/relaton_bsi/version.rb
104
106
  - lib/relaton_bsi/xml_parser.rb
105
107
  - relaton_bsi.gemspec