relaton-gb 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: af59eecad25f703949530ba1d289daac5eafea562bf4453b56e92e5951747ffa
4
- data.tar.gz: 7c6dcf93299919fe1869fb91c93f556382d129d1cfdc69c69c4d09027cfdb1ee
3
+ metadata.gz: 77a65c710fb3f90a55360e83741f5fabe4e19cd5e7af7c7f3c9fe9407b0da29e
4
+ data.tar.gz: 81b88ce4507b1d6b91ea4dcee2179369b9139a1cc6799ec52d179bbc8c15db16
5
5
  SHA512:
6
- metadata.gz: c45e0158f52768fa4e1468794c9ec78a207db0105f8dc285368c6cde561c1f5695b85dd1699bf2b48a84ac703a6e74f363962536fc8df50c0389bf3055e6a0c8
7
- data.tar.gz: 8fd2778d0a2a78f5301666bc5615d7ddf73f2ec627d80ea254cd669915dbad1fcf33aa72ab2db24e50cd702faf85077403909e3d0b717d2e3a0474bd88ca6c20
6
+ metadata.gz: 8bf26e37145d5c50a3f55e90d6d330adb9f76b1e9faa9670eda7629174355c793c5b3182e791d42ac346c17275d5d393b776ed31ebf920fca6408e72a6172295
7
+ data.tar.gz: 7bbdae2269caf3045f7af542700d0366a46733561135c5704c52fef0be2d0e8ca79bc19a59e9bb28396267fa2aa9bd8fbd68ac9522eda80f685bc3fd537168a9
data/README.adoc CHANGED
@@ -39,14 +39,26 @@ Or install it yourself as:
39
39
 
40
40
  == Usage
41
41
 
42
- === Search document
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.
43
45
 
44
46
  [source,ruby]
45
47
  ----
46
48
  require 'relaton_gb'
47
49
  => true
48
50
 
51
+ RelatonGb.configure do |config|
52
+ config.logger.level = Logger::DEBUG
53
+ end
54
+ ----
55
+
56
+ === Search document
57
+
58
+ [source,ruby]
59
+ ----
49
60
  hit_collection = RelatonGb::GbBibliography.search "GB/T 20223-2006"
61
+ [relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
50
62
  => <RelatonGb::HitCollection:0x007fc8d8a26d10 @ref= @fetched=false>
51
63
 
52
64
  hit_collection.first
@@ -64,7 +76,7 @@ hit_collection.first.fetch.committee
64
76
  => #<RelatonGb::GbTechnicalCommittee:0x007f975713c450 @name="中国纤维检验局", @type="technical">
65
77
 
66
78
  hit_collection.first.fetch.gbtype
67
- => #<RelatonGb::GbStandardType:0x007f9758087018 @mandate="recommended", @prefix="GB_national", @scope="national">
79
+ => #<RelatonGb::GbStandardType:0x0000000112957dc0 @mandate="recommended", @prefix="GB_national", @scope="national", @topic="other">
68
80
 
69
81
  hit_collection.first.fetch.ccs
70
82
  => [#<Cnccs::Ccs:0x007f975713c090
@@ -77,21 +89,43 @@ hit_collection.first.fetch.ccs
77
89
  @subgroupcode="32">]
78
90
 
79
91
  hit_collection.first.fetch.title
80
- => [#<RelatonIsoBib::TypedTitleString:0x007f975714cfa8
81
- @title=#<RelatonBib::FormattedString:0x007f975714cb20 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
82
- @type="title-main">,
83
- #<RelatonIsoBib::TypedTitleString:0x007f975714c580
84
- @title=#<RelatonBib::FormattedString:0x007f9757147f08 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
85
- @type="main">,
86
- #<RelatonIsoBib::TypedTitleString:0x007f97571477d8
87
- @title=#<RelatonBib::FormattedString:0x007f9757146ec8 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
88
- @type="title-main">,
89
- #<RelatonIsoBib::TypedTitleString:0x007f97571465e0
90
- @title=#<RelatonBib::FormattedString:0x007f9757146158 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
91
- @type="main">]
92
+ => #<RelatonBib::TypedTitleStringCollection:0x0000000112a1ac08
93
+ @array=
94
+ [#<RelatonBib::TypedTitleString:0x0000000112a1f438
95
+ @title=#<RelatonBib::FormattedString:0x0000000112cd6050 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
96
+ @type="title-main">,
97
+ #<RelatonBib::TypedTitleString:0x0000000112a1eb78
98
+ @title=#<RelatonBib::FormattedString:0x0000000112cd6000 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
99
+ @type="main">,
100
+ #<RelatonBib::TypedTitleString:0x0000000112a1c198
101
+ @title=#<RelatonBib::FormattedString:0x0000000112cd5ce0 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
102
+ @type="title-main">,
103
+ #<RelatonBib::TypedTitleString:0x0000000112a1bba8
104
+ @title=#<RelatonBib::FormattedString:0x0000000112cd5c40 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
105
+ @type="main">]>
92
106
 
93
107
  hit_collection.first.fetch.date
94
- => [#<RelatonBib::BibliographicDate:0x007f975a0207d0 @from=nil, @on=2006-03-10 00:00:00 +0100, @to=nil, @type="published">]
108
+ => [#<RelatonBib::BibliographicDate:0x000000011307f468 @from=nil, @on="2006-03-10", @to=nil, @type="published">]
109
+ ----
110
+
111
+ === Get document by identifier
112
+
113
+ [source,ruby]
114
+ ----
115
+ RelatonGb::GbBibliography.get "GB/T 20223-2006"
116
+ [relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
117
+ [relaton-gb] (GB/T 20223-2006) Found: `GB/T 20223-2006`
118
+ => <RelatonGb::GbBibliographicItem:0x000000000011f8>
119
+ ----
120
+
121
+ === Get document by identifier and year
122
+
123
+ [source,ruby]
124
+ ----
125
+ RelatonGb::GbBibliography.get "GB/T 20223", "2006"
126
+ [relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
127
+ [relaton-gb] (GB/T 20223-2006) Found: `GB/T 20223-2006`
128
+ => <RelatonGb::GbBibliographicItem:0x00000000001248>
95
129
  ----
96
130
 
97
131
  === Create bibliographic item from YAML
@@ -0,0 +1,10 @@
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
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "relaton_iso_bib"
4
- require "cnccs"
5
3
  require "relaton_gb/gb_technical_committee"
6
4
  require "relaton_gb/gb_standard_type"
7
5
  require "relaton_gb/xml_parser"
@@ -11,6 +9,8 @@ require "relaton_gb/ccs"
11
9
  module RelatonGb
12
10
  # GB bibliographic item class.
13
11
  class GbBibliographicItem < RelatonIsoBib::IsoBibliographicItem
12
+ DOCTYPES = %w[standard reccomendation].freeze
13
+
14
14
  # @return [RelatonGb::GbTechnicalCommittee]
15
15
  attr_reader :committee
16
16
 
@@ -15,10 +15,11 @@ module RelatonGb
15
15
  # @return [RelatonGb::HitCollection]
16
16
  def search(text)
17
17
  case text
18
- # when /^(GB|GJ|GS)/
18
+ when /^(GB|GJ|GS)/
19
19
  # Scrape national standards.
20
- # require "relaton_gb/gb_scrapper"
21
- # GbScrapper.scrape_page text
20
+ Util.warn "(#{text}) Fetching from openstd.samr.gov.cn ..."
21
+ require "relaton_gb/gb_scrapper"
22
+ GbScrapper.scrape_page text
22
23
  # when /^ZB/
23
24
  # Scrape proffesional.
24
25
  # when /^DB/
@@ -27,6 +28,7 @@ module RelatonGb
27
28
  # Enterprise standard
28
29
  when %r{^T/[^\s]{2,6}\s}
29
30
  # Scrape social standard.
31
+ Util.warn "(#{text}) Fetching from www.ttbz.org.cn ..."
30
32
  require "relaton_gb/t_scrapper"
31
33
  TScrapper.scrape_page text
32
34
  else
@@ -42,7 +44,7 @@ module RelatonGb
42
44
  # @param year [String] the year the standard was published (optional)
43
45
  # @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
44
46
  # @return [String] Relaton XML serialisation of reference
45
- def get(code, year = nil, opts = {})
47
+ def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
46
48
  if year.nil?
47
49
  /^(?<code1>[^-]+)-(?<year1>[^-]+)$/ =~ code
48
50
  unless code1.nil?
@@ -52,7 +54,7 @@ module RelatonGb
52
54
  end
53
55
 
54
56
  code += ".1" if opts[:all_parts]
55
- code, year = code.split(/-/, 2) if /-/ =~ code
57
+ code, year = code.split("-", 2) if code.include?("-")
56
58
  ret = get1(code, year, opts)
57
59
  return nil if ret.nil?
58
60
 
@@ -63,22 +65,22 @@ module RelatonGb
63
65
 
64
66
  private
65
67
 
66
- def fetch_ref_err(code, year, missed_years)
67
- id = year ? "#{code}:#{year}" : code
68
- warn "[relaton-gb] WARNING: no match found on the GB website "\
69
- "for #{id}. The code must be exactly like it is on the website."
68
+ def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
69
+ # id = year ? "#{code}:#{year}" : code
70
+ # Util.warn "WARNING: No match found on the GB website for `#{id}`. " \
71
+ # "The code must be exactly like it is on the website."
70
72
  unless missed_years.empty?
71
- warn "[relaton-gb] (There was no match for #{year}, though there "\
72
- "were matches found for #{missed_years.join(', ')}.)"
73
+ Util.warn "(There was no match for `#{year}`, though there " \
74
+ "were matches found for `#{missed_years.join('`, `')}`.)"
73
75
  end
74
76
  if /\d-\d/.match? code
75
- warn "[relaton-gb] The provided document part may not exist, or the "\
76
- "document may no longer be published in parts."
77
+ Util.warn "The provided document part may not exist, or " \
78
+ "the document may no longer be published in parts."
77
79
  else
78
- warn "[relaton-gb] If you wanted to cite all document parts for the "\
79
- "reference, use \"#{code} (all parts)\".\nIf the document is not "\
80
- "a standard, use its document type abbreviation (TS, TR, PAS, "\
81
- "Guide)."
80
+ Util.warn "If you wanted to cite all document parts for the " \
81
+ "reference, use `#{code} (all parts)`.\nIf the document " \
82
+ "is not a standard, use its document type abbreviation " \
83
+ "(TS, TR, PAS, Guide)."
82
84
  end
83
85
  nil
84
86
  end
@@ -89,9 +91,10 @@ module RelatonGb
89
91
  result = search_filter(searchcode) || return
90
92
  ret = results_filter(result, year)
91
93
  if ret[:ret]
92
- warn "[relaton-gb] (\"#{code}\") found #{ret[:ret].docidentifier.first.id}"
94
+ Util.warn "(#{searchcode}) Found: `#{ret[:ret].docidentifier.first.id}`"
93
95
  ret[:ret]
94
96
  else
97
+ Util.warn "(#{searchcode}) Not found."
95
98
  fetch_ref_err(code, year, ret[:years])
96
99
  end
97
100
  end
@@ -99,7 +102,6 @@ module RelatonGb
99
102
  def search_filter(code)
100
103
  # search filter needs to incorporate year
101
104
  docidrx = %r{^[^\s]+\s[\d.-]+}
102
- warn "[relaton-gb] (\"#{code}\") fetching..."
103
105
  result = search(code)
104
106
  result.select do |hit|
105
107
  hit.docref && hit.docref.match(docidrx).to_s.include?(code)
@@ -0,0 +1,9 @@
1
+ module RelatonGb
2
+ module Util
3
+ extend RelatonBib::Util
4
+
5
+ def self.logger
6
+ RelatonGb.configuration.logger
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonGb
4
- VERSION = "1.16.0"
4
+ VERSION = "1.16.2"
5
5
  end
data/lib/relaton_gb.rb CHANGED
@@ -1,6 +1,10 @@
1
+ require "digest/md5"
2
+ require "relaton_iso_bib"
3
+ require "cnccs"
1
4
  require "relaton_gb/version"
5
+ require "relaton_gb/config"
6
+ require "relaton_gb/util"
2
7
  require "relaton_gb/gb_bibliography"
3
- require "digest/md5"
4
8
 
5
9
  # if defined? Relaton
6
10
  # require "relaton_gb/processor"
@@ -14,9 +18,9 @@ module RelatonGb
14
18
  # Returns hash of XML reammar
15
19
  # @return [String]
16
20
  def self.grammar_hash
17
- gem_path = File.expand_path "..", __dir__
18
- grammars_path = File.join gem_path, "grammars", "*"
19
- grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
20
- Digest::MD5.hexdigest grammars
21
+ # gem_path = File.expand_path "..", __dir__
22
+ # grammars_path = File.join gem_path, "grammars", "*"
23
+ # grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
24
+ Digest::MD5.hexdigest RelatonGb::VERSION + RelatonIsoBib::VERSION + RelatonBib::VERSION # grammars
21
25
  end
22
26
  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.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-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cnccs
@@ -80,6 +80,7 @@ files:
80
80
  - grammars/relaton-gb.rng
81
81
  - lib/relaton_gb.rb
82
82
  - lib/relaton_gb/ccs.rb
83
+ - lib/relaton_gb/config.rb
83
84
  - lib/relaton_gb/gb_bibliographic_item.rb
84
85
  - lib/relaton_gb/gb_bibliography.rb
85
86
  - lib/relaton_gb/gb_scrapper.rb
@@ -92,6 +93,7 @@ files:
92
93
  - lib/relaton_gb/scrapper.rb
93
94
  - lib/relaton_gb/sec_scrapper.rb
94
95
  - lib/relaton_gb/t_scrapper.rb
96
+ - lib/relaton_gb/util.rb
95
97
  - lib/relaton_gb/version.rb
96
98
  - lib/relaton_gb/xml_parser.rb
97
99
  - lib/relaton_gb/yaml/prefixes.yaml