relaton-itu 1.7.4 → 1.7.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +1 -5
- data/bin/rspec +29 -0
- data/lib/relaton_itu.rb +1 -0
- data/lib/relaton_itu/hash_converter.rb +9 -0
- data/lib/relaton_itu/hit.rb +1 -1
- data/lib/relaton_itu/hit_collection.rb +17 -6
- data/lib/relaton_itu/itu_bibliographic_item.rb +7 -0
- data/lib/relaton_itu/itu_bibliography.rb +27 -12
- data/lib/relaton_itu/processor.rb +1 -2
- data/lib/relaton_itu/scrapper.rb +50 -56
- data/lib/relaton_itu/version.rb +1 -1
- data/relaton-itu.gemspec +2 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b1e5e668d61b87b432757af973484271e9c36d509e1a18b2e28b9989af178c7
|
4
|
+
data.tar.gz: 0f58ebbe769409d733e036e9e49f248590fc40a0bdacebdea27b7443c37a161a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c12e668eb24ebb6691677652d87ecf3d3aae8d3f82cf2d99693896bc55bc77395c51bca0049d5c3c8d12e1cd58321d98e16ae3b42f8a2d38a945955255ccbb25
|
7
|
+
data.tar.gz: 8a1335624162c8e0c9cf4db764a3d1dec58e735f15d4fde2410d742f7e622d4e4185e31bbb87c838d2eab0d16e984167797b29ebc29a3b405914aeb04c158015
|
data/README.adoc
CHANGED
@@ -127,11 +127,7 @@ hash = YAML.load_file 'spec/examples/itu_bib_item.yml'
|
|
127
127
|
=> {"id"=>"ITU-T L.163 (11/2018)",
|
128
128
|
...
|
129
129
|
|
130
|
-
|
131
|
-
=> {:id=>"ITU-T L.163 (11/2018)",
|
132
|
-
...
|
133
|
-
|
134
|
-
RelatonItu::ItuBibliographicItem.new bib_hash
|
130
|
+
RelatonItu::ItuBibliographicItem.from_hash hash
|
135
131
|
=> #<RelatonItu::ItuBibliographicItem:0x007fd88ac02aa0
|
136
132
|
...
|
137
133
|
----
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/lib/relaton_itu.rb
CHANGED
@@ -3,6 +3,15 @@ module RelatonItu
|
|
3
3
|
class << self
|
4
4
|
private
|
5
5
|
|
6
|
+
#
|
7
|
+
# Ovverides superclass's method
|
8
|
+
#
|
9
|
+
# @param item [Hash]
|
10
|
+
# @retirn [RelatonItu::ItuBibliographicItem]
|
11
|
+
def bib_item(item)
|
12
|
+
ItuBibliographicItem.new(**item)
|
13
|
+
end
|
14
|
+
|
6
15
|
def editorialgroup_hash_to_bib(ret)
|
7
16
|
eg = ret[:editorialgroup]
|
8
17
|
return unless eg
|
data/lib/relaton_itu/hit.rb
CHANGED
@@ -12,22 +12,32 @@ module RelatonItu
|
|
12
12
|
# @return [TrueClass, FalseClass]
|
13
13
|
attr_reader :gi_imp
|
14
14
|
|
15
|
+
# @return [Mechanize]
|
16
|
+
attr_reader :agent
|
17
|
+
|
15
18
|
# @param ref [String]
|
16
19
|
# @param year [String]
|
17
20
|
def initialize(ref, year = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
18
21
|
text = ref.sub /(?<=\.)Imp\s?(?=\d)/, ""
|
19
22
|
super text, year
|
23
|
+
@agent = Mechanize.new
|
24
|
+
agent.user_agent_alias = "Mac Safari"
|
20
25
|
@gi_imp = /\.Imp\d/.match?(ref)
|
21
26
|
if ref.match? /^(ITU-T|ITU-R\sRR)/
|
22
|
-
|
27
|
+
url = "#{DOMAIN}/net4/ITU-T/search/GlobalSearch/Search"
|
23
28
|
data = { json: params.to_json }
|
24
|
-
resp =
|
25
|
-
"Content-Type" => "application/json")
|
29
|
+
resp = agent.post url, data.to_json, "Content-Type" => "application/json"
|
26
30
|
@array = hits JSON.parse(resp.body)
|
27
31
|
elsif ref.match? /^ITU-R/
|
28
32
|
rf = ref.sub(/^ITU-R\s/, "").upcase
|
29
33
|
url = "https://raw.githubusercontent.com/relaton/relaton-data-itu-r/master/data/#{rf}.yaml"
|
30
|
-
|
34
|
+
resp = Net::HTTP.get_response(URI(url))
|
35
|
+
if resp.code == "404"
|
36
|
+
@array = []
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
hash = YAML.safe_load resp.body
|
31
41
|
item_hash = HashConverter.hash_to_bib(hash)
|
32
42
|
item = ItuBibliographicItem.new **item_hash
|
33
43
|
hit = Hit.new({ url: url }, self)
|
@@ -41,7 +51,8 @@ module RelatonItu
|
|
41
51
|
# @return [String]
|
42
52
|
def group
|
43
53
|
@group ||= case text
|
44
|
-
when %r{OB|Operational Bulletin}, %r{^ITU-R\sRR}
|
54
|
+
when %r{OB|Operational Bulletin}, %r{^ITU-R\sRR}
|
55
|
+
"Publications"
|
45
56
|
when %r{^ITU-T} then "Recommendations"
|
46
57
|
end
|
47
58
|
end
|
@@ -105,7 +116,7 @@ module RelatonItu
|
|
105
116
|
code = h["Media"]["Name"]
|
106
117
|
title = h["Title"]
|
107
118
|
url = h["Redirection"]
|
108
|
-
type =
|
119
|
+
type = h["Collection"]["Group"].downcase[0...-1]
|
109
120
|
Hit.new({ code: code, title: title, url: url, type: type }, self)
|
110
121
|
end
|
111
122
|
end
|
@@ -19,16 +19,23 @@ module RelatonItu
|
|
19
19
|
# @param text [String]
|
20
20
|
# @return [RelatonItu::HitCollection]
|
21
21
|
def search(text, year = nil)
|
22
|
+
# code = text.sub(/(?<=ITU-T\s\w)\.(\w+\.)(?=\d+)/, ' \1')
|
23
|
+
if text =~ /(ITU-T\s\w)\.(Suppl\.|Annex)\s?(\w?\d+)/
|
24
|
+
correct_ref = "#{$~[1]} #{$~[2]} #{$~[3]}"
|
25
|
+
warn "[relaton-itu] WARNING: Incorrect reference #{text}"
|
26
|
+
warn "[relaton-itu] the reference should be #{correct_ref}"
|
27
|
+
end
|
22
28
|
HitCollection.new text, year
|
23
29
|
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
|
24
30
|
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
25
|
-
Net::ProtocolError,
|
26
|
-
raise RelatonBib::RequestError,
|
31
|
+
Net::ProtocolError, URI::InvalidURIError => e
|
32
|
+
raise RelatonBib::RequestError, e.message
|
27
33
|
end
|
28
34
|
|
29
35
|
# @param code [String] the ISO standard Code to look up (e..g "ISO 9000")
|
30
36
|
# @param year [String] the year the standard was published (optional)
|
31
|
-
# @param opts [Hash] options; restricted to :all_parts if all-parts
|
37
|
+
# @param opts [Hash] options; restricted to :all_parts if all-parts
|
38
|
+
# reference is required
|
32
39
|
# @return [String] Relaton XML serialisation of reference
|
33
40
|
def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
34
41
|
if year.nil?
|
@@ -55,12 +62,12 @@ module RelatonItu
|
|
55
62
|
warn "[relaton-itu] WARNING: no match found online for #{id}. "\
|
56
63
|
"The code must be exactly like it is on the standards website."
|
57
64
|
unless missed_years.empty?
|
58
|
-
warn "[relaton-itu] (There was no match for #{year}, though there
|
59
|
-
"found for #{missed_years.join(', ')}.)"
|
65
|
+
warn "[relaton-itu] (There was no match for #{year}, though there "\
|
66
|
+
"were matches found for #{missed_years.join(', ')}.)"
|
60
67
|
end
|
61
68
|
if /\d-\d/.match? code
|
62
|
-
warn "[relaton-itu] The provided document part may not exist, or
|
63
|
-
"may no longer be published in parts."
|
69
|
+
warn "[relaton-itu] The provided document part may not exist, or "\
|
70
|
+
"the document may no longer be published in parts."
|
64
71
|
else
|
65
72
|
warn "[relaton-itu] If you wanted to cite all document parts for the reference, "\
|
66
73
|
"use \"#{code} (all parts)\".\nIf the document is not a standard, "\
|
@@ -71,10 +78,11 @@ module RelatonItu
|
|
71
78
|
|
72
79
|
def search_filter(code, year) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
73
80
|
%r{
|
74
|
-
^(?<pref1>ITU)?(-(?<type1>\w))?\s?(?<code1>[^\s\/]+)
|
81
|
+
^(?<pref1>ITU)?(-(?<type1>\w))?\s?(?<code1>[^\s\/]+(?:\/\w[\.\d]+)?)
|
82
|
+
(\s\(?(?<ver1>v\d+)\)?)?
|
75
83
|
(\s\(((?<month1>\d{2})\/)?(?<year1>\d{4})\))?
|
76
84
|
(\s-\s(?<buldate1>\d{2}\.\w{1,4}\.\d{4}))?
|
77
|
-
(
|
85
|
+
(\s(?<corr1>(Amd|Cor|Amendment|Corrigendum)\.?\s?\d+))?
|
78
86
|
(\s\(((?<cormonth1>\d{2})\/)?(?<coryear1>\d{4})\))?
|
79
87
|
}x =~ code
|
80
88
|
year ||= year1
|
@@ -83,21 +91,27 @@ module RelatonItu
|
|
83
91
|
warn "[relaton-itu] (\"#{code}\") fetching..."
|
84
92
|
result = search(code)
|
85
93
|
code1.sub! /(?<=\.)Imp(?=\d)/, "" if result.gi_imp
|
94
|
+
if corr1
|
95
|
+
corr1.sub!(/[\.\s]+/, " ").sub!("Amendment", "Amd")
|
96
|
+
corr1.sub!("Corrigendum", "Corr")
|
97
|
+
end
|
86
98
|
result.select do |i|
|
87
99
|
next true unless i.hit[:code]
|
88
100
|
|
89
101
|
%r{
|
90
102
|
^(?<pref2>ITU)?(-(?<type2>\w))?\s?(?<code2>[\S]+)
|
103
|
+
(\s\(?(?<ver2>v\d+)\)?)?
|
91
104
|
(\s\(((?<month2>\d{2})\/)?(?<year2>\d{4})\))?
|
92
105
|
(\s(?<corr2>(Amd|Cor)\.\s?\d+))?
|
93
106
|
(\s\(((?<cormonth2>\d{2})\/)?(?<coryear2>\d{4})\))?
|
94
107
|
}x =~ i.hit[:code]
|
95
108
|
/:[^\(]+\((?<buldate2>\d{2}\.\w{1,4}\.\d{4})\)/ =~ i.hit[:title]
|
96
109
|
corr2&.sub! /\.\s?/, " "
|
97
|
-
pref1 == pref2 && (!type1 || type1 == type2) && code1
|
110
|
+
pref1 == pref2 && (!type1 || type1 == type2) && code2.include?(code1) &&
|
98
111
|
(!year || year == year2) && (!month1 || month1 == month2) &&
|
99
112
|
corr1 == corr2 && (!coryear1 || coryear1 == coryear2) &&
|
100
|
-
buldate1 == buldate2 && (!cormonth1 || cormonth1 == cormonth2)
|
113
|
+
buldate1 == buldate2 && (!cormonth1 || cormonth1 == cormonth2) &&
|
114
|
+
(!ver1 || ver1 == ver2)
|
101
115
|
end
|
102
116
|
end
|
103
117
|
|
@@ -110,7 +124,8 @@ module RelatonItu
|
|
110
124
|
def isobib_results_filter(result, year)
|
111
125
|
missed_years = []
|
112
126
|
result.each do |r|
|
113
|
-
|
127
|
+
/\((\d{2}\/)?(?<pyear>\d{4})\)/ =~ r.hit[:code]
|
128
|
+
if !year || year == pyear
|
114
129
|
ret = r.fetch
|
115
130
|
return { ret: ret } if ret
|
116
131
|
end
|
@@ -26,8 +26,7 @@ module RelatonItu
|
|
26
26
|
# @param hash [Hash]
|
27
27
|
# @return [RelatonItu::ItuBibliographicItem]
|
28
28
|
def hash_to_bib(hash)
|
29
|
-
|
30
|
-
::RelatonItu::ItuBibliographicItem.new item_hash
|
29
|
+
::RelatonItu::ItuBibliographicItem.from_hash hash
|
31
30
|
end
|
32
31
|
|
33
32
|
# Returns hash of XML grammar
|
data/lib/relaton_itu/scrapper.rb
CHANGED
@@ -24,20 +24,18 @@ module RelatonItu
|
|
24
24
|
}.freeze
|
25
25
|
|
26
26
|
class << self
|
27
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
28
|
-
|
29
27
|
# Parse page.
|
30
|
-
# @param
|
28
|
+
# @param hit [RelatonItu::Hit]
|
31
29
|
# @return [Hash]
|
32
|
-
def parse_page(
|
33
|
-
|
34
|
-
return unless doc
|
30
|
+
def parse_page(hit, imp = false) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
31
|
+
doc = get_page hit
|
32
|
+
return unless doc.code == "200"
|
35
33
|
|
36
34
|
if imp
|
37
35
|
a = doc.at "//span[contains(@id, 'tab_ig_uc_rec')]/a"
|
38
36
|
return unless a
|
39
37
|
|
40
|
-
|
38
|
+
doc = get_page hit, a[:href].to_s
|
41
39
|
end
|
42
40
|
|
43
41
|
# Fetch edition.
|
@@ -46,36 +44,37 @@ module RelatonItu
|
|
46
44
|
ItuBibliographicItem.new(
|
47
45
|
fetched: Date.today.to_s,
|
48
46
|
type: "standard",
|
49
|
-
docid: fetch_docid(doc,
|
47
|
+
docid: fetch_docid(doc, hit.hit[:title]),
|
50
48
|
edition: edition,
|
51
49
|
language: ["en"],
|
52
50
|
script: ["Latn"],
|
53
51
|
title: fetch_titles(doc),
|
54
|
-
doctype:
|
52
|
+
doctype: hit.hit[:type],
|
55
53
|
docstatus: fetch_status(doc),
|
56
54
|
ics: [], # fetch_ics(doc),
|
57
55
|
date: fetch_dates(doc),
|
58
|
-
contributor: fetch_contributors(
|
59
|
-
editorialgroup: fetch_workgroup(
|
60
|
-
abstract: fetch_abstract(doc),
|
61
|
-
copyright: fetch_copyright(
|
62
|
-
link: fetch_link(doc
|
56
|
+
contributor: fetch_contributors(hit.hit[:code]),
|
57
|
+
editorialgroup: fetch_workgroup(hit.hit[:code], doc),
|
58
|
+
abstract: fetch_abstract(doc, hit),
|
59
|
+
copyright: fetch_copyright(hit.hit[:code], doc),
|
60
|
+
link: fetch_link(doc),
|
63
61
|
relation: fetch_relations(doc),
|
64
62
|
place: ["Geneva"]
|
65
63
|
)
|
66
64
|
end
|
67
|
-
# rubocop:enable Metrics/AbcSize
|
68
65
|
|
69
66
|
private
|
70
67
|
|
71
68
|
# Fetch abstracts.
|
72
|
-
# @param doc [
|
73
|
-
# @
|
74
|
-
|
75
|
-
|
69
|
+
# @param doc [Mechanize::Page]
|
70
|
+
# @param hit [RelatonItu::Hit]
|
71
|
+
# @return [Array<Hash>]
|
72
|
+
def fetch_abstract(doc, hit) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
73
|
+
abstract_url = doc.at '//table/tr[td/span[.="In force"]]/td/span[contains(@id, "lbl_dms")]/div'
|
76
74
|
content = if abstract_url
|
77
75
|
url = abstract_url[:onclick].match(/https?[^']+/).to_s
|
78
|
-
|
76
|
+
rsp = hit.hit_collection.agent.get url
|
77
|
+
d = Nokogiri::HTML rsp.body.encode(undef: :replace, replace: "")
|
79
78
|
d.css("p.MsoNormal").text.gsub(/\r\n/, "").squeeze(" ").gsub(/\u00a0/, "")
|
80
79
|
elsif a = doc.at('//table/tr/td/span[contains(@class, "observation")]/text()')
|
81
80
|
a.text.strip
|
@@ -90,27 +89,20 @@ module RelatonItu
|
|
90
89
|
end
|
91
90
|
|
92
91
|
# Get page.
|
93
|
-
# @param
|
92
|
+
# @param hit [RelatonItu::Hit]
|
93
|
+
# @param url [String, nil]
|
94
94
|
# @return [Array<String, Nokogiri::HTML::Document>]
|
95
|
-
def get_page(url)
|
96
|
-
uri =
|
97
|
-
|
98
|
-
until resp.code == "200"
|
99
|
-
return if resp["location"] == "/en/publications/pages/notfound.aspx"
|
100
|
-
|
101
|
-
uri = URI resp["location"] if resp.code.match? /^30/
|
102
|
-
resp = Net::HTTP.get_response(uri)
|
103
|
-
end
|
104
|
-
[uri.to_s, Nokogiri::HTML(resp.body)]
|
95
|
+
def get_page(hit, url = nil)
|
96
|
+
uri = url || hit.hit[:url]
|
97
|
+
hit.hit_collection.agent.get uri
|
105
98
|
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
|
106
99
|
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
107
100
|
Net::ProtocolError, OpenSSL::SSL::SSLError
|
108
|
-
raise RelatonBib::RequestError, "Could not access #{
|
101
|
+
raise RelatonBib::RequestError, "Could not access #{uri}"
|
109
102
|
end
|
110
|
-
# rubocop:enable Metrics/MethodLength
|
111
103
|
|
112
104
|
# Fetch docid.
|
113
|
-
# @param doc [
|
105
|
+
# @param doc [Mechanize::Page]
|
114
106
|
# @param title [String]
|
115
107
|
# @return [Hash]
|
116
108
|
def fetch_docid(doc, title)
|
@@ -123,6 +115,8 @@ module RelatonItu
|
|
123
115
|
docids
|
124
116
|
end
|
125
117
|
|
118
|
+
# @param text [String]
|
119
|
+
# @return [RelatonBib::DocumentIdentifier]
|
126
120
|
def createdocid(text) # rubocop:disable Metrics/MethodLength
|
127
121
|
%r{
|
128
122
|
^(?<code>((ITU-\w|ISO\/IEC)\s)?[^\(:]+)
|
@@ -132,7 +126,7 @@ module RelatonItu
|
|
132
126
|
# (\s\(((?<_cormonth>\d{2})\/)?(?<_coryear>\d{4})\))?
|
133
127
|
}x =~ text.squeeze(" ")
|
134
128
|
corr&.sub! /\.\s?/, " "
|
135
|
-
id = [code.sub(/[[:space:]]$/, ""), corr].compact.join "
|
129
|
+
id = [code.sub(/[[:space:]]$/, ""), corr].compact.join " "
|
136
130
|
id += " - #{buldate}" if buldate
|
137
131
|
type = id.match(%r{^\w+}).to_s
|
138
132
|
type = "ITU" if type == "G"
|
@@ -140,7 +134,7 @@ module RelatonItu
|
|
140
134
|
end
|
141
135
|
|
142
136
|
# Fetch status.
|
143
|
-
# @param doc [
|
137
|
+
# @param doc [Mechanize::Page]
|
144
138
|
# @return [RelatonBib::DocumentStatus, NilClass]
|
145
139
|
def fetch_status(doc)
|
146
140
|
s = doc.at("//table/tr/td/span[contains(@id, 'Label7')]",
|
@@ -153,7 +147,7 @@ module RelatonItu
|
|
153
147
|
|
154
148
|
# Fetch workgroup.
|
155
149
|
# @param code [String]
|
156
|
-
# @param doc [
|
150
|
+
# @param doc [Mechanize::Page]
|
157
151
|
# @return [RelatonItu::EditorialGroup, NilClass]
|
158
152
|
def fetch_workgroup(code, doc)
|
159
153
|
wg = doc.at('//table/tr/td/span[contains(@id, "Label8")]/a')
|
@@ -161,8 +155,7 @@ module RelatonItu
|
|
161
155
|
|
162
156
|
group = wg && itugroup(wg.text)
|
163
157
|
EditorialGroup.new(
|
164
|
-
bureau: code.match(/(?<=-)./).to_s,
|
165
|
-
group: group
|
158
|
+
bureau: code.match(/(?<=-)./).to_s, group: group
|
166
159
|
)
|
167
160
|
end
|
168
161
|
|
@@ -182,24 +175,24 @@ module RelatonItu
|
|
182
175
|
ItuGroup.new name: name, type: type, acronym: acronym
|
183
176
|
end
|
184
177
|
|
185
|
-
# rubocop:disable Metrics/MethodLength
|
186
|
-
|
187
178
|
# Fetch relations.
|
188
|
-
# @param doc [
|
179
|
+
# @param doc [Mechanize::Page]
|
189
180
|
# @return [Array<Hash>]
|
190
181
|
def fetch_relations(doc)
|
191
|
-
doc.xpath('//div[contains(@id, "tab_sup")]//table/tr[position()>2]')
|
182
|
+
doc.xpath('//div[contains(@id, "tab_sup")]//table/tr[position()>2]')
|
183
|
+
.map do |r|
|
192
184
|
ref = r.at('./td/span[contains(@id, "title_e")]/nobr/a')
|
193
|
-
fref = RelatonBib::FormattedRef.new(content: ref.text, language: "en",
|
194
|
-
|
185
|
+
fref = RelatonBib::FormattedRef.new(content: ref.text, language: "en",
|
186
|
+
script: "Latn")
|
187
|
+
bibitem = ItuBibliographicItem.new(formattedref: fref,
|
188
|
+
type: "standard")
|
195
189
|
{ type: "complements", bibitem: bibitem }
|
196
190
|
end
|
197
191
|
end
|
198
|
-
# rubocop:enable Metrics/MethodLength
|
199
192
|
|
200
193
|
# Fetch titles.
|
201
|
-
# @param doc [
|
202
|
-
# @return [
|
194
|
+
# @param doc [Mechanize::Page]
|
195
|
+
# @return [RelatonBib::TypedTitleStringCollection]
|
203
196
|
def fetch_titles(doc)
|
204
197
|
t = doc.at("//td[@class='title']|//div/table[1]/tr[4]/td/strong")
|
205
198
|
return [] unless t
|
@@ -208,7 +201,7 @@ module RelatonItu
|
|
208
201
|
end
|
209
202
|
|
210
203
|
# Fetch dates
|
211
|
-
# @param doc [
|
204
|
+
# @param doc [Mechanize::Page]
|
212
205
|
# @return [Array<Hash>]
|
213
206
|
def fetch_dates(doc) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
214
207
|
dates = []
|
@@ -224,7 +217,7 @@ module RelatonItu
|
|
224
217
|
end
|
225
218
|
|
226
219
|
# Scrape Operational Bulletin date.
|
227
|
-
# @param doc [
|
220
|
+
# @param doc [Mechanize::Page]
|
228
221
|
# @return [String]
|
229
222
|
def ob_date(doc)
|
230
223
|
pdate = doc.at('//table/tbody/tr/td[contains(text(), "Year:")]')
|
@@ -246,7 +239,7 @@ module RelatonItu
|
|
246
239
|
end
|
247
240
|
|
248
241
|
# Fetch contributors
|
249
|
-
# @param doc [
|
242
|
+
# @param doc [Mechanize::Page]
|
250
243
|
# @return [Array<Hash>]
|
251
244
|
def fetch_contributors(code)
|
252
245
|
return [] unless code
|
@@ -262,11 +255,10 @@ module RelatonItu
|
|
262
255
|
end
|
263
256
|
|
264
257
|
# Fetch links.
|
265
|
-
# @param doc [
|
266
|
-
# @param url [String]
|
258
|
+
# @param doc [Mechanize::Page]
|
267
259
|
# @return [Array<Hash>]
|
268
|
-
def fetch_link(doc
|
269
|
-
links = [{ type: "src", content:
|
260
|
+
def fetch_link(doc)
|
261
|
+
links = [{ type: "src", content: doc.uri.to_s }]
|
270
262
|
obp_elm = doc.at(
|
271
263
|
'//a[@title="Persistent link to download the PDF file"]',
|
272
264
|
"//font[contains(.,'PDF')]/../.."
|
@@ -277,6 +269,8 @@ module RelatonItu
|
|
277
269
|
links
|
278
270
|
end
|
279
271
|
|
272
|
+
# @param type [String]
|
273
|
+
# @param elm [Nokogiri::XML::Element]
|
280
274
|
def typed_link(type, elm)
|
281
275
|
{
|
282
276
|
type: type,
|
@@ -286,7 +280,7 @@ module RelatonItu
|
|
286
280
|
|
287
281
|
# Fetch copyright.
|
288
282
|
# @param code [String]
|
289
|
-
# @param doc [
|
283
|
+
# @param doc [Mechanize::Page]
|
290
284
|
# @return [Array<Hash>]
|
291
285
|
def fetch_copyright(code, doc)
|
292
286
|
abbreviation = code.match(/^[^-]+/).to_s
|
data/lib/relaton_itu/version.rb
CHANGED
data/relaton-itu.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
# spec.add_development_dependency "debase"
|
30
30
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
31
31
|
spec.add_development_dependency "pry-byebug"
|
32
|
-
spec.add_development_dependency "rake", "~>
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
34
|
# spec.add_development_dependency "ruby-debug-ide"
|
35
35
|
spec.add_development_dependency "ruby-jing"
|
@@ -37,5 +37,6 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_development_dependency "vcr", "~> 5.0.0"
|
38
38
|
spec.add_development_dependency "webmock"
|
39
39
|
|
40
|
+
spec.add_dependency "mechanize"
|
40
41
|
spec.add_dependency "relaton-bib", "~> 1.7.0"
|
41
42
|
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.7.
|
4
|
+
version: 1.7.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equivalent-xml
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: mechanize
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: relaton-bib
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,6 +167,7 @@ files:
|
|
153
167
|
- README.adoc
|
154
168
|
- Rakefile
|
155
169
|
- bin/console
|
170
|
+
- bin/rspec
|
156
171
|
- bin/setup
|
157
172
|
- grammars/basicdoc.rng
|
158
173
|
- grammars/biblio.rng
|