relaton-itu 1.16.1 → 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: ba25af96c755b3ba32e9318e989f3a7396538c23667112dcde1282fd22b64c4b
4
- data.tar.gz: 1757b9672eeeae25548c7cf2ea3c6f2fb7beb9dbdc5740b452177e20540fc4dc
3
+ metadata.gz: 443de281f4001442162f16fb86986ab597616e3ae2981a44efe8ae9fccaa0a2b
4
+ data.tar.gz: 4389f4b0d42563047b6bb7cd927b95872f0ec0a18a5ef377e900df1f2646b473
5
5
  SHA512:
6
- metadata.gz: adc9864ea7e48260cb0aa5550b0fbaa2a4943359537acaf75a974514f9a034dd34a01842da5abd2b5b65cffb796f022dbb5f8527fc1addcd915e4646340eb502
7
- data.tar.gz: 24b824c4af92c5aa195abd7681f9e24f370450555cef3018e67280257eccc0b6e4290a70c2270406f70e0714cbc5c651b2d1fdf94d4babff2ca37209a0455918
6
+ metadata.gz: bac3b34ee7dd29bb81d34e684e10310c0d4496745e610fce3bc20668b8ae17ec85171823b9b48d8709137086d7d2171edbf702bc16b7b0956506a95b6273a60a
7
+ data.tar.gz: 52e8ddec0d293ab9dbe4f0c1ece20562aaf2ea838bca96f3ec423d16117be291251f4cc7b655117fa3edd18e341ecc38559b79e46b8903ac6c1f781c7eefd89b
data/README.adoc CHANGED
@@ -29,13 +29,24 @@ Or install it yourself as:
29
29
 
30
30
  == Usage
31
31
 
32
- === Search for a standard using keywords
32
+ === Configuration
33
+
34
+ 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 `RelatonItu.configure` block.
33
35
 
34
36
  [source,ruby]
35
37
  ----
36
38
  require 'relaton_itu'
37
39
  => true
38
40
 
41
+ RelatonItu.configure do |config|
42
+ config.logger.level = Logger::DEBUG
43
+ end
44
+ ----
45
+
46
+ === Search for a standard using keywords
47
+
48
+ [source,ruby]
49
+ ----
39
50
  hit_collection = RelatonItu::ItuBibliography.search("ITU-T L.163")
40
51
  => <RelatonItu::HitCollection:0x007fbf5fb4ab60 @ref=ITU-T L.163 @fetched=false>
41
52
 
@@ -73,8 +84,8 @@ item.to_xml bibdata: true
73
84
  [source,ruby]
74
85
  ----
75
86
  RelatonItu::ItuBibliography.get("ITU-T L.163", "2018", {})
76
- [relaton-itu] ("ITU-T L.163") fetching...
77
- [relaton-itu] ("ITU-T L.163") found ITU-T L.163
87
+ [relaton-itu] (ITU-T L.163) Fetching from www.itu.int ...
88
+ [relaton-itu] (ITU-T L.163) Found: `ITU-T L.163`
78
89
  => #<RelatonItu::ItuBibliographicItem:0x007fbf5f94b9b8
79
90
  ...
80
91
  ----
@@ -83,8 +94,8 @@ RelatonItu::ItuBibliography.get("ITU-T L.163", "2018", {})
83
94
  [source,ruby]
84
95
  ----
85
96
  RelatonItu::ItuBibliography.get "ITU-T G.989.2/Amd 1"
86
- [relaton-itu] ("ITU-T G.989.2/Amd 1") fetching...
87
- [relaton-itu] ("ITU-T G.989.2/Amd 1") found ITU-T G.989.2/Amd 1
97
+ [relaton-itu] (ITU-T G.989.2/Amd 1) Fetching from www.itu.int ...
98
+ [relaton-itu] (ITU-T G.989.2/Amd 1) Found: `ITU-T G.989.2/Amd 1`
88
99
  => #<RelatonItu::ItuBibliographicItem:0x007fe5409e5840
89
100
  ...
90
101
  ----
@@ -94,8 +105,8 @@ RelatonItu::ItuBibliography.get "ITU-T G.989.2/Amd 1"
94
105
  [source,ruby]
95
106
  ----
96
107
  RelatonItu::ItuBibliography.get "ITU-R BO.600-1"
97
- [relaton-itu] ("ITU-R BO.600-1") fetching...
98
- [relaton-itu] ("ITU-R BO.600-1") found ITU-R BO.600-1
108
+ [relaton-itu] (ITU-R BO.600-1) Fetching from www.itu.int ...
109
+ [relaton-itu] (ITU-R BO.600-1) Found: `ITU-R BO.600-1`
99
110
  => #<RelatonItu::ItuBibliographicItem:0x00007fb0cf8a1308
100
111
  ...
101
112
  ----
@@ -105,9 +116,9 @@ RelatonItu::ItuBibliography.get "ITU-R BO.600-1"
105
116
  [source,ruby]
106
117
  ----
107
118
  RelatonItu::ItuBibliography.get 'ITU-R RR (2020)'
108
- [relaton-itu] ("ITU-R RR") fetching...
109
- [relaton-itu] WARNING: invalid doctype: publication
110
- [relaton-itu] ("ITU-R RR") found ITU-R RR
119
+ [relaton-itu] (ITU-R RR) Fetching from www.itu.int ...
120
+ [relaton-itu] WARNING: Invalid doctype: `publication`
121
+ [relaton-itu] (ITU-R RR) Found: ITU-R RR
111
122
  => #<RelatonItu::ItuBibliographicItem:0x007fb4b55eb660
112
123
  ...
113
124
  ----
@@ -17,8 +17,8 @@ module RelatonItu
17
17
  # @param workgroup [Hash, RelatonItu::ItuGroup, NilClass]
18
18
  def initialize(bureau:, group:, subgroup: nil, workgroup: nil)
19
19
  unless BUREAUS.include? bureau
20
- Util.warn "WARNING: invalid bureau: `#{bureau}`"
21
- Util.warn "WARNING: valid bureaus are: `#{BUREAUS.join('`, `')}`"
20
+ Util.warn "WARNING: Invalid bureau: `#{bureau}`"
21
+ Util.warn "WARNING: Valid bureaus are: `#{BUREAUS.join('`, `')}`"
22
22
  end
23
23
  @bureau = bureau
24
24
  @group = group.is_a?(Hash) ? ItuGroup.new(**group) : group
@@ -21,6 +21,7 @@ module RelatonItu
21
21
  # @param refid [RelatonItu::Pubid] reference
22
22
  #
23
23
  def initialize(refid) # rubocop:todo Metrics/MethodLength
24
+ @refid = refid
24
25
  text = refid.to_ref.sub(/(?<=\.)Imp\s?(?=\d)/, "")
25
26
  super text, refid.year
26
27
  @agent = Mechanize.new
@@ -32,25 +33,24 @@ module RelatonItu
32
33
  when /^(ITU-T|ITU-R\sRR)/
33
34
  request_search
34
35
  when /^ITU-R\s/
35
- request_document(refid)
36
+ request_document
36
37
  end
37
38
  end
38
39
 
39
40
  private
40
41
 
41
42
  def request_search
43
+ Util.warn "(#{@refid}) Fetching from www.itu.int ..."
42
44
  url = "#{DOMAIN}/net4/ITU-T/search/GlobalSearch/RunSearch"
43
45
  data = { json: params.to_json }
44
46
  resp = agent.post url, data
45
47
  @array = hits JSON.parse(resp.body)
46
48
  end
47
49
 
48
- #
49
- # @param refid [RelatonItu::Pubid] a document reference
50
- #
51
- def request_document(refid) # rubocop:todo Metrics/MethodLength, Metrics/AbcSize
50
+ def request_document # rubocop:todo Metrics/MethodLength, Metrics/AbcSize
51
+ Util.warn "(#{@refid}) Fetching from Relaton repository ..."
52
52
  index = Relaton::Index.find_or_create :itu, url: "#{GH_ITU_R}index-v1.zip", file: INDEX_FILE
53
- row = index.search(refid.to_ref).min_by { |i| i[:id] }
53
+ row = index.search(@refid.to_ref).min_by { |i| i[:id] }
54
54
  return unless row
55
55
 
56
56
  uri = URI("#{GH_ITU_R}#{row[:file]}")
@@ -77,8 +77,10 @@ module RelatonItu
77
77
 
78
78
  # @return [Hash]
79
79
  def params # rubocop:disable Metrics/MethodLength
80
+ input = @refid.dup
81
+ input.year = nil
80
82
  {
81
- "Input" => text,
83
+ "Input" => input.to_s,
82
84
  "Start" => 0,
83
85
  "Rows" => 10,
84
86
  "SortBy" => "RELEVANCE",
@@ -10,7 +10,7 @@ module RelatonItu
10
10
  # @params structuredidentifier [RelatonItu::StructuredIdentifier]
11
11
  def initialize(**args)
12
12
  if args[:doctype] && !TYPES.include?(args[:doctype])
13
- Util.warn "WARNING: invalid doctype: `#{args[:doctype]}`"
13
+ Util.warn "WARNING: Invalid doctype: `#{args[:doctype]}`"
14
14
  end
15
15
  super
16
16
  end
@@ -22,9 +22,9 @@ module RelatonItu
22
22
  def search(refid)
23
23
  refid = RelatonItu::Pubid.parse refid if refid.is_a? String
24
24
  if refid.to_ref =~ /(ITU[\s-]T\s\w)\.(Suppl\.|Annex)\s?(\w?\d+)/
25
- correct_ref = "`#{$~[1]}` `#{$~[2]}` `#{$~[3]}`"
26
- Util.warn "WARNING: Incorrect reference `#{refid}`"
27
- Util.warn "the reference should be #{correct_ref}"
25
+ correct_ref = "#{$~[1]} #{$~[2]} #{$~[3]}"
26
+ Util.warn "WARNING: Incorrect reference: `#{refid}`"
27
+ Util.warn "the reference should be: `#{correct_ref}`"
28
28
  end
29
29
  HitCollection.new refid
30
30
  rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse,
@@ -63,19 +63,21 @@ module RelatonItu
63
63
  private
64
64
 
65
65
  def fetch_ref_err(refid, missed_years) # rubocop:disable Metrics/MethodLength
66
- Util.warn "WARNING: no match found online for `#{refid}`. " \
67
- "The code must be exactly like it is on the standards website."
68
- unless missed_years.empty?
69
- Util.warn "(There was no match for `#{refid.year}`, though there " \
70
- "were matches found for `#{missed_years.join('`, `')}`.)"
66
+ # Util.warn "WARNING: no match found online for `#{refid}`. " \
67
+ # "The code must be exactly like it is on the standards website."
68
+ Util.warn "(#{refid}) Not found."
69
+ if missed_years.any?
70
+ plural = missed_years.size > 1 ? "s" : ""
71
+ Util.warn "(#{refid}) There was no match for `#{refid.year}` year, though " \
72
+ "there were matches found for `#{missed_years.join('`, `')}` year#{plural}."
71
73
  end
72
74
  # if /\d-\d/.match? refid.code
73
75
  # warn "[relaton-itu] The provided document part may not exist, or " \
74
76
  # "the document may no longer be published in parts."
75
77
  # else
76
- Util.warn "If you wanted to cite all document parts for the reference, " \
77
- "use `#{refid} (all parts)`.\nIf the document is not a standard, " \
78
- "use its document type abbreviation `S`, `TR`, `PAS`, `Guide`)."
78
+ # Util.warn "If you wanted to cite all document parts for the reference, " \
79
+ # "use `#{refid} (all parts)`.\nIf the document is not a standard, " \
80
+ # "use its document type abbreviation `S`, `TR`, `PAS`, `Guide`)."
79
81
  # end
80
82
  nil
81
83
  end
@@ -90,7 +92,6 @@ module RelatonItu
90
92
  # (?:\s\((?:(?<cormonth1>\d{2})/)?(?<coryear1>\d{4})\))?
91
93
  # }x =~ code
92
94
  # year ||= year1
93
- Util.warn "(#{refid}) fetching..."
94
95
  result = search(refid)
95
96
  # refid.code.sub!(/(?<=\.)Imp(?=\d)/, "") if result.gi_imp
96
97
  # if corr1
@@ -101,7 +102,7 @@ module RelatonItu
101
102
  next true unless i.hit[:code]
102
103
 
103
104
  pubid = Pubid.parse i.hit[:code]
104
- refid === pubid
105
+ refid.===(pubid, [:year])
105
106
  # %r{
106
107
  # ^(?<pref2>ITU)?(?:-(?<type2>\w))?\s?(?<code2>\S+)
107
108
  # (?:\s\(?(?<ver2>v\d+)\)?)?
@@ -143,7 +144,7 @@ module RelatonItu
143
144
  result = search_filter(refid) || return
144
145
  ret = isobib_results_filter(result, refid)
145
146
  if ret[:ret]
146
- Util.warn "(#{refid}) found `#{ret[:ret].docidentifier.first&.id}`"
147
+ Util.warn "(#{refid}) Found: `#{ret[:ret].docidentifier.first&.id}`"
147
148
  ret[:ret]
148
149
  else
149
150
  fetch_ref_err(refid, ret[:years])
@@ -65,8 +65,8 @@ module RelatonItu
65
65
  id_parts = Parser.new.parse(id).to_h.transform_values(&:to_s)
66
66
  new(**id_parts)
67
67
  rescue Parslet::ParseFailed => e
68
- warn "[relaton-itu] WARNING: #{id} is invalid ITU publication identifier"
69
- warn e.parse_failure_cause.ascii_tree
68
+ Util.warn "WARNING: `#{id}` is invalid ITU publication identifier \n" \
69
+ "#{e.parse_failure_cause.ascii_tree}"
70
70
  raise e
71
71
  end
72
72
 
@@ -96,11 +96,12 @@ module RelatonItu
96
96
  s
97
97
  end
98
98
 
99
- def ===(other)
99
+ def ===(other, ignore_args = [])
100
100
  hash = to_h with_type: false
101
101
  other_hash = other.to_h with_type: false
102
102
  hash.delete(:month)
103
103
  other_hash.delete(:month)
104
+ hash.delete(:year) if ignore_args.include?(:year)
104
105
  other_hash.delete(:year) unless hash[:year]
105
106
  hash == other_hash
106
107
  end
@@ -75,7 +75,7 @@ module RelatonItu
75
75
  url = abstract_url[:onclick].match(/https?[^']+/).to_s
76
76
  rsp = hit.hit_collection.agent.get url
77
77
  d = Nokogiri::HTML rsp.body.encode(undef: :replace, replace: "")
78
- d.css("p.MsoNormal").text.gsub(/\r\n/, "").squeeze(" ").gsub(/\u00a0/, "")
78
+ d.css("p.MsoNormal").text.gsub("\r\n", "").squeeze(" ").gsub("\u00a0", "")
79
79
  elsif a = doc.at('//table/tr/td/span[contains(@class, "observation")]/text()')
80
80
  a.text.strip
81
81
  end
@@ -87,7 +87,7 @@ module RelatonItu
87
87
  script: "Latn",
88
88
  }]
89
89
  rescue Mechanize::ResponseCodeError => e
90
- warn "HTTP Service Unavailable: #{e.message}"
90
+ Util.warn "HTTP Service Unavailable: #{e.message}"
91
91
  []
92
92
  end
93
93
 
@@ -11,7 +11,7 @@ module RelatonItu
11
11
  # @param annexid [String, NilClass]
12
12
  def initialize(bureau:, docnumber:, annexid: nil)
13
13
  unless EditorialGroup::BUREAUS.include? bureau
14
- warn "[relaton-itu] WARNING: invalid bureau: #{bureau}"
14
+ Util.warn "WARNING: Invalid bureau: `#{bureau}`"
15
15
  end
16
16
  @bureau = bureau
17
17
  @docnumber = docnumber
@@ -1,3 +1,3 @@
1
1
  module RelatonItu
2
- VERSION = "1.16.1".freeze
2
+ VERSION = "1.16.2".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-itu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.1
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-21 00:00:00.000000000 Z
11
+ date: 2023-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize