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 +4 -4
- data/README.adoc +5 -12
- data/grammars/basicdoc.rng +3 -0
- data/lib/relaton_gb/document_type.rb +1 -1
- data/lib/relaton_gb/gb_bibliographic_item.rb +12 -8
- data/lib/relaton_gb/gb_bibliography.rb +8 -8
- data/lib/relaton_gb/hash_converter.rb +8 -2
- data/lib/relaton_gb/util.rb +1 -4
- data/lib/relaton_gb/version.rb +1 -1
- data/lib/relaton_gb/xml_parser.rb +4 -0
- data/lib/relaton_gb.rb +0 -1
- data/relaton_gb.gemspec +1 -1
- metadata +7 -8
- data/lib/relaton_gb/config.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a6f089b0e88176b0a975002a00cc353ecddc6f611721b89886f5578b047a893
|
4
|
+
data.tar.gz: c962a506d4d9b6359c9ae7e041ae78a6dd61d3b096bfa12833e19cdb8404556c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
===
|
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.
|
data/grammars/basicdoc.rng
CHANGED
@@ -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] &&
|
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
|
-
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
94
|
+
Util.info "Found: `#{ret[:ret].docidentifier.first.id}`", key: searchcode
|
95
95
|
ret[:ret]
|
96
96
|
else
|
97
|
-
Util.
|
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]
|
31
|
-
|
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
|
|
data/lib/relaton_gb/util.rb
CHANGED
data/lib/relaton_gb/version.rb
CHANGED
data/lib/relaton_gb.rb
CHANGED
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.
|
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.
|
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-
|
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.
|
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.
|
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.'
|