relaton-gb 1.18.4 → 1.20.0

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: a01690064106c099fc8b4cf2531876232bc3d2a4fd4b41622d4337a0707ce080
4
- data.tar.gz: 972a0679b5e1474d3ef0d9c8afefb49157dc0da042c89f736693e4ddb9b9531f
3
+ metadata.gz: 1a6f089b0e88176b0a975002a00cc353ecddc6f611721b89886f5578b047a893
4
+ data.tar.gz: c962a506d4d9b6359c9ae7e041ae78a6dd61d3b096bfa12833e19cdb8404556c
5
5
  SHA512:
6
- metadata.gz: 6b8a4c456f5984105065c294a7566a9f679e16e534d36eda56c0024f5504fd378ba364d6b299039a47a9edb1a8d4d2c3f69193df0b9c683f76cbb11ec7c02031
7
- data.tar.gz: cd21352325f87070a8f0ab29a28a3bb31c2c53efca18c59d7bd642dec02cec896ed4eefdcc5e972e4e8ee546687fdced7aecb6932bd96e0b904a2244f9195ff9
6
+ metadata.gz: 03e7d65e846285ae4c246b6b0d5c17cda499391413ff49254a535aa0a7413699c740fa736a620291963dacd0d02d16af23b58f2825426a0c45a9c6d1437017a7
7
+ data.tar.gz: 19ee5ac1b544b344bd051515d14b3558dd6b71eeed66228a8178b5ab6c4c54f322b3ff12a585569e2866334641553a36fcc63bd95da7618f8d3dd6a49c48266c
data/README.adoc CHANGED
@@ -39,24 +39,13 @@ Or install it yourself as:
39
39
 
40
40
  == Usage
41
41
 
42
- === Configuration
43
-
44
- 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 `RelatonGb.configure` block.
42
+ === Search document
45
43
 
46
44
  [source,ruby]
47
45
  ----
48
46
  require 'relaton_gb'
49
47
  => true
50
48
 
51
- RelatonGb.configure do |config|
52
- config.logger.level = Logger::DEBUG
53
- end
54
- ----
55
-
56
- === Search document
57
-
58
- [source,ruby]
59
- ----
60
49
  hit_collection = RelatonGb::GbBibliography.search "GB/T 20223-2006"
61
50
  [relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
62
51
  => <RelatonGb::HitCollection:0x007fc8d8a26d10 @ref= @fetched=false>
@@ -182,6 +171,10 @@ hit_collection.first.fetch.link
182
171
  => [#<RelatonBib::TypedUri:0x00007fee2c0257e8 @content=#<Addressable::URI:0x67c URI:http://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=083B48FA72DBD3B9BDE74507BC31736A>, @type="src">]
183
172
  ----
184
173
 
174
+ === Logging
175
+
176
+ RelatonGb uses the relaton-logger gem for logging. By default, it logs to STDOUT. To change the log levels and add other loggers, read the https://github.com/relaton/relaton-logger#usage[relaton-logger] documentation.
177
+
185
178
  == Development
186
179
 
187
180
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -244,6 +244,9 @@
244
244
  <data type="ID"/>
245
245
  </attribute>
246
246
  <attribute name="reviewer"/>
247
+ <optional>
248
+ <attribute name="type"/>
249
+ </optional>
247
250
  <optional>
248
251
  <attribute name="date">
249
252
  <data type="dateTime"/>
@@ -9,7 +9,7 @@ module RelatonGb
9
9
 
10
10
  def check_type(type)
11
11
  unless DOCTYPES.include? type
12
- Util.warn "WARNING: invalid doctype: `#{type}`"
12
+ Util.warn "invalid doctype: `#{type}`"
13
13
  end
14
14
  end
15
15
  end
@@ -57,7 +57,7 @@ module RelatonGb
57
57
  # @return [String] XML
58
58
  def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
59
59
  super(**opts) do |b|
60
- if opts[:bibdata] && has_ext_attrs?
60
+ if opts[:bibdata] && has_ext?
61
61
  ext = b.ext do
62
62
  doctype&.to_xml b
63
63
  b.horizontal horizontal unless horizontal.nil?
@@ -76,13 +76,17 @@ module RelatonGb
76
76
  # @return [Hash]
77
77
  def to_hash # rubocop:disable Metrics/AbcSize
78
78
  hash = super
79
- hash["ccs"] = single_element_array(ccs) if ccs&.any?
80
- hash["committee"] = committee.to_hash if committee
81
- hash["plannumber"] = gbplannumber if gbplannumber
82
- hash["gbtype"] = gbtype.to_hash
79
+ hash["ext"]["ccs"] = single_element_array(ccs) if ccs&.any?
80
+ hash["ext"]["committee"] = committee.to_hash if committee
81
+ hash["ext"]["plannumber"] = gbplannumber if gbplannumber
82
+ hash["ext"]["gbtype"] = gbtype.to_hash if gbtype
83
83
  hash
84
84
  end
85
85
 
86
+ def has_ext?
87
+ super || ccs&.any? || committee || gbplannumber || gbtype
88
+ end
89
+
86
90
  # @param prefix [String]
87
91
  # @return [String]
88
92
  def to_asciibib(prefix = "")
@@ -128,8 +132,8 @@ module RelatonGb
128
132
  #
129
133
  # @return [Boolean]
130
134
  #
131
- def has_ext_attrs?
132
- super || committee || docsubtype
133
- end
135
+ # def has_ext_attrs?
136
+ # super || committee || docsubtype
137
+ # end
134
138
  end
135
139
  end
@@ -17,7 +17,7 @@ module RelatonGb
17
17
  case text
18
18
  when /^(GB|GJ|GS)/
19
19
  # Scrape national standards.
20
- Util.warn "(#{text}) Fetching from openstd.samr.gov.cn ..."
20
+ Util.info "Fetching from openstd.samr.gov.cn ...", key: text
21
21
  require "relaton_gb/gb_scrapper"
22
22
  GbScrapper.scrape_page text
23
23
  # when /^ZB/
@@ -28,7 +28,7 @@ module RelatonGb
28
28
  # Enterprise standard
29
29
  when %r{^T/[^\s]{2,6}\s}
30
30
  # Scrape social standard.
31
- Util.warn "(#{text}) Fetching from www.ttbz.org.cn ..."
31
+ Util.info "Fetching from www.ttbz.org.cn ...", key: text
32
32
  require "relaton_gb/t_scrapper"
33
33
  TScrapper.scrape_page text
34
34
  else
@@ -67,17 +67,17 @@ module RelatonGb
67
67
 
68
68
  def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
69
69
  # id = year ? "#{code}:#{year}" : code
70
- # Util.warn "WARNING: No match found on the GB website for `#{id}`. " \
70
+ # Util.info "WARNING: No match found on the GB website for `#{id}`. " \
71
71
  # "The code must be exactly like it is on the website."
72
72
  unless missed_years.empty?
73
- Util.warn "(There was no match for `#{year}`, though there " \
73
+ Util.info "(There was no match for `#{year}`, though there " \
74
74
  "were matches found for `#{missed_years.join('`, `')}`.)"
75
75
  end
76
76
  if /\d-\d/.match? code
77
- Util.warn "The provided document part may not exist, or " \
77
+ Util.info "The provided document part may not exist, or " \
78
78
  "the document may no longer be published in parts."
79
79
  else
80
- Util.warn "If you wanted to cite all document parts for the " \
80
+ Util.info "If you wanted to cite all document parts for the " \
81
81
  "reference, use `#{code} (all parts)`.\nIf the document " \
82
82
  "is not a standard, use its document type abbreviation " \
83
83
  "(TS, TR, PAS, Guide)."
@@ -91,10 +91,10 @@ module RelatonGb
91
91
  result = search_filter(searchcode) || return
92
92
  ret = results_filter(result, year)
93
93
  if ret[:ret]
94
- Util.warn "(#{searchcode}) Found: `#{ret[:ret].docidentifier.first.id}`"
94
+ Util.info "Found: `#{ret[:ret].docidentifier.first.id}`", key: searchcode
95
95
  ret[:ret]
96
96
  else
97
- Util.warn "(#{searchcode}) Not found."
97
+ Util.info "Not found.", key: searchcode
98
98
  fetch_ref_err(code, year, ret[:years])
99
99
  end
100
100
  end
@@ -11,6 +11,9 @@ module RelatonGb
11
11
  ret = super
12
12
  return if ret.nil?
13
13
 
14
+ ret[:committee] = ret[:ext][:committee] if ret.dig(:ext, :committee)
15
+ ret[:plannumber] = ret[:ext][:plannumber] if ret.dig(:ext, :plannumber)
16
+ ret[:gbtype] = ret[:ext][:gbtype] if ret.dig(:ext, :gbtype)
14
17
  ccs_hash_to_bib(ret)
15
18
  ret
16
19
  end
@@ -27,8 +30,11 @@ module RelatonGb
27
30
  end
28
31
 
29
32
  def ccs_hash_to_bib(ret)
30
- ret[:ccs] = RelatonBib.array(ret[:ccs]).map do |ccs|
31
- (ccs[:code] && Cnccs.fetch(ccs[:code])) || Cnccs.fetch(ccs)
33
+ ccs = ret.dig(:ext, :ccs) || ret[:ccs] # @TODO: remove ret[:ccs] after all specs are updated
34
+ return unless ccs
35
+
36
+ ret[:ccs] = RelatonBib.array(ccs).map do |item|
37
+ (item[:code] && Cnccs.fetch(item[:code])) || Cnccs.fetch(item)
32
38
  end
33
39
  end
34
40
 
@@ -1,9 +1,6 @@
1
1
  module RelatonGb
2
2
  module Util
3
3
  extend RelatonBib::Util
4
-
5
- def self.logger
6
- RelatonGb.configuration.logger
7
- end
4
+ PROGNAME = "relaton-gb".freeze
8
5
  end
9
6
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonGb
4
- VERSION = "1.18.4"
4
+ VERSION = "1.20.0"
5
5
  end
@@ -41,6 +41,10 @@ module RelatonGb
41
41
  topic: gbtype&.at("gbtopic")&.text,
42
42
  }
43
43
  end
44
+
45
+ def create_doctype(type)
46
+ DocumentType.new type: type.text, abbreviation: type[:abbreviation]
47
+ end
44
48
  end
45
49
  end
46
50
  end
data/lib/relaton_gb.rb CHANGED
@@ -3,7 +3,6 @@ require "mechanize"
3
3
  require "relaton_iso_bib"
4
4
  require "cnccs"
5
5
  require "relaton_gb/version"
6
- require "relaton_gb/config"
7
6
  require "relaton_gb/util"
8
7
  require "relaton_gb/document_type"
9
8
  require "relaton_gb/gb_bibliography"
data/relaton_gb.gemspec CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency "cnccs", "~> 0.1.1"
28
28
  spec.add_dependency "gb-agencies", "~> 0.0.1"
29
29
  spec.add_dependency "mechanize", "~> 2.10"
30
- spec.add_dependency "relaton-iso-bib", "~> 1.18.0"
30
+ spec.add_dependency "relaton-iso-bib", "~> 1.20.0"
31
31
  spec.add_dependency "csv", "~> 3.0"
32
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-gb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.4
4
+ version: 1.20.0
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: 2024-06-19 00:00:00.000000000 Z
11
+ date: 2024-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cnccs
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.18.0
61
+ version: 1.20.0
62
62
  type: :runtime
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: 1.18.0
68
+ version: 1.20.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: csv
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,6 @@ files:
108
108
  - grammars/relaton-gb.rng
109
109
  - lib/relaton_gb.rb
110
110
  - lib/relaton_gb/ccs.rb
111
- - lib/relaton_gb/config.rb
112
111
  - lib/relaton_gb/document_type.rb
113
112
  - lib/relaton_gb/gb_bibliographic_item.rb
114
113
  - lib/relaton_gb/gb_bibliography.rb
@@ -131,7 +130,7 @@ homepage: https://github.com/metanorma/relaton_gb
131
130
  licenses:
132
131
  - BSD-2-Clause
133
132
  metadata: {}
134
- post_install_message:
133
+ post_install_message:
135
134
  rdoc_options: []
136
135
  require_paths:
137
136
  - lib
@@ -147,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
146
  version: '0'
148
147
  requirements: []
149
148
  rubygems_version: 3.3.27
150
- signing_key:
149
+ signing_key:
151
150
  specification_version: 4
152
151
  summary: 'RelatonGb: retrieve Chinese GB Standards for bibliographic use using the
153
152
  BibliographicItem model.'
@@ -1,10 +0,0 @@
1
- module RelatonGb
2
- module Config
3
- include RelatonBib::Config
4
- end
5
- extend Config
6
-
7
- class Configuration < RelatonBib::Configuration
8
- PROGNAME = "relaton-gb".freeze
9
- end
10
- end