relaton-iec 1.7.4 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +46 -0
- data/README.adoc +230 -1
- data/bin/rspec +29 -0
- data/grammars/basicdoc.rng +165 -20
- data/grammars/biblio.rng +4 -6
- data/grammars/iec.rng +92 -1
- data/grammars/isodoc.rng +460 -6
- data/grammars/isostandard.rng +42 -104
- data/grammars/reqt.rng +31 -2
- data/lib/relaton_iec.rb +71 -7
- data/lib/relaton_iec/basic_block/alignment.rb +30 -0
- data/lib/relaton_iec/basic_block/basic_block.rb +15 -0
- data/lib/relaton_iec/basic_block/citation_type.rb +32 -0
- data/lib/relaton_iec/basic_block/dl.rb +60 -0
- data/lib/relaton_iec/basic_block/eref.rb +10 -0
- data/lib/relaton_iec/basic_block/eref_type.rb +39 -0
- data/lib/relaton_iec/basic_block/formula.rb +34 -0
- data/lib/relaton_iec/basic_block/image.rb +41 -0
- data/lib/relaton_iec/basic_block/index.rb +27 -0
- data/lib/relaton_iec/basic_block/index_xref.rb +31 -0
- data/lib/relaton_iec/basic_block/note.rb +21 -0
- data/lib/relaton_iec/basic_block/paragraph.rb +27 -0
- data/lib/relaton_iec/basic_block/paragraph_with_footnote.rb +29 -0
- data/lib/relaton_iec/basic_block/reference_format.rb +38 -0
- data/lib/relaton_iec/basic_block/stem.rb +30 -0
- data/lib/relaton_iec/basic_block/table.rb +115 -0
- data/lib/relaton_iec/basic_block/text_element.rb +27 -0
- data/lib/relaton_iec/hash_converter.rb +1 -1
- data/lib/relaton_iec/hit.rb +4 -0
- data/lib/relaton_iec/hit_collection.rb +31 -12
- data/lib/relaton_iec/iec_bibliographic_item.rb +92 -0
- data/lib/relaton_iec/iec_bibliography.rb +82 -49
- data/lib/relaton_iec/processor.rb +7 -2
- data/lib/relaton_iec/scrapper.rb +12 -40
- data/lib/relaton_iec/statuses.yml +84 -17
- data/lib/relaton_iec/tc_sc_officers_note.rb +24 -0
- data/lib/relaton_iec/version.rb +1 -1
- data/lib/relaton_iec/xml_parser.rb +21 -1
- data/relaton_iec.gemspec +3 -3
- metadata +25 -36
- data/.github/workflows/macos.yml +0 -34
- data/.github/workflows/ubuntu.yml +0 -33
- data/.github/workflows/windows.yml +0 -35
@@ -0,0 +1,27 @@
|
|
1
|
+
module BasicBlock
|
2
|
+
class TextElement
|
3
|
+
TAGS = %w[em strong sub sup tt underline strike smallcap br hr keyword rp
|
4
|
+
rt ruby pagebreak bookmark].freeze
|
5
|
+
|
6
|
+
#
|
7
|
+
# @param [String] tag
|
8
|
+
# @param [Array<String, BasicBlock::TextElement, BasicBlock::Stem>,
|
9
|
+
# String] content
|
10
|
+
#
|
11
|
+
def initialize(tag:, content:)
|
12
|
+
unless TAGS.include? tag
|
13
|
+
warn "[basic-block] WARNING: invalid tag \"#{tag}\""
|
14
|
+
warn "[basic-block] allowed tags are: #{TAGS.join ', '}"
|
15
|
+
end
|
16
|
+
@tag = tag
|
17
|
+
@content = content
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param [Nokogiri::XML::Builder]
|
21
|
+
def to_xml(builder)
|
22
|
+
builder.send @tag do |b|
|
23
|
+
@content.each { |c| c.is_a?(String) ? c : c.to_xml(b) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/relaton_iec/hit.rb
CHANGED
@@ -6,50 +6,69 @@ require "addressable/uri"
|
|
6
6
|
module RelatonIec
|
7
7
|
# Page of hit collection.
|
8
8
|
class HitCollection < RelatonBib::HitCollection
|
9
|
+
def_delegators :@array, :detect
|
10
|
+
|
11
|
+
attr_reader :part
|
12
|
+
|
9
13
|
DOMAIN = "https://webstore.iec.ch"
|
10
14
|
|
11
|
-
# @param
|
15
|
+
# @param ref [String]
|
12
16
|
# @param year [String, nil]
|
13
17
|
# @param part [String, nil]
|
14
|
-
def initialize(
|
15
|
-
super
|
16
|
-
@
|
18
|
+
def initialize(ref, year = nil, part = nil)
|
19
|
+
super ref, year
|
20
|
+
@part = part
|
21
|
+
@array = ref ? hits(ref, year) : []
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [RelatonIec::IecBibliographicItem]
|
25
|
+
def to_all_parts # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity
|
26
|
+
parts = @array.reject { |h| h.part.nil? }
|
27
|
+
hit = parts.min_by &:part
|
28
|
+
return @array.first&.fetch unless hit
|
29
|
+
|
30
|
+
bibitem = hit.fetch
|
31
|
+
all_parts_item = bibitem.to_all_parts
|
32
|
+
parts.reject { |h| h.hit[:code] == hit.hit[:code] }.each do |hi|
|
33
|
+
isobib = RelatonIec::IecBibliographicItem.new(
|
34
|
+
formattedref: RelatonBib::FormattedRef.new(content: hi.hit[:code])
|
35
|
+
)
|
36
|
+
all_parts_item.relation << RelatonBib::DocumentRelation.new(type: "partOf", bibitem: isobib)
|
37
|
+
end
|
38
|
+
all_parts_item
|
17
39
|
end
|
18
40
|
|
19
41
|
private
|
20
42
|
|
21
43
|
# @param ref [String]
|
22
44
|
# @param year [String, nil]
|
23
|
-
# @param part [String, nil]
|
24
45
|
# @return [Array<RelatonIec::Hit>]
|
25
|
-
def hits(ref, year
|
46
|
+
def hits(ref, year)
|
26
47
|
from, to = nil
|
27
48
|
if year
|
28
49
|
from = Date.strptime year, "%Y"
|
29
50
|
to = from.next_year.prev_day
|
30
51
|
end
|
31
|
-
get_results ref, from, to
|
52
|
+
get_results ref, from, to
|
32
53
|
end
|
33
54
|
|
34
55
|
# @param ref [String]
|
35
56
|
# @param from [Date, nil]
|
36
57
|
# @param to [Date, nil]
|
37
|
-
# @param part [String, nil]
|
38
58
|
# @return [Array<RelatonIec::Hit>]
|
39
|
-
def get_results(ref, from, to
|
59
|
+
def get_results(ref, from, to)
|
40
60
|
code = part ? ref.sub(/(?<=-\d)\d+/, "*") : ref
|
41
61
|
[nil, "trf", "wr"].reduce([]) do |m, t|
|
42
62
|
url = "#{DOMAIN}/searchkey"
|
43
63
|
url += "&type=#{t}" if t
|
44
64
|
url += "&RefNbr=#{code}&From=#{from}&To=#{to}&start=1"
|
45
|
-
m + results(Addressable::URI.parse(url).normalize
|
65
|
+
m + results(Addressable::URI.parse(url).normalize)
|
46
66
|
end
|
47
67
|
end
|
48
68
|
|
49
69
|
# @param url [String]
|
50
|
-
# @param part [String, nil]
|
51
70
|
# @return [Array<RelatonIec::Hit>]
|
52
|
-
def results(uri
|
71
|
+
def results(uri)
|
53
72
|
contains = "[contains(.,'Part #{part}:')]" if part
|
54
73
|
resp = OpenURI.open_uri(uri, "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) "\
|
55
74
|
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36")
|
@@ -5,5 +5,97 @@ module RelatonIec
|
|
5
5
|
publicly-available-specification international-workshop-agreement
|
6
6
|
guide
|
7
7
|
].freeze
|
8
|
+
|
9
|
+
FUNCTION = %w[emc safety enviroment quality-assurance].freeze
|
10
|
+
|
11
|
+
# @return [String, nil]
|
12
|
+
attr_reader :function, :updates_document_type, :price_code, :secretary,
|
13
|
+
:interest_to_committees
|
14
|
+
|
15
|
+
# @return [Boolean, nil]
|
16
|
+
attr_reader :accessibility_color_inside, :cen_processing
|
17
|
+
|
18
|
+
# attr_reader :tc_sc_officers_note
|
19
|
+
|
20
|
+
def initialize(**args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
21
|
+
if args[:function] && !FUNCTION.include?(args[:function])
|
22
|
+
warn "[relaton-iec] WARNING: invalid function \"#{args[:function]}\""
|
23
|
+
warn "[relaton-iec] allowed function values are: #{FUNCTION.join(', ')}"
|
24
|
+
end
|
25
|
+
if args[:updates_document_type] &&
|
26
|
+
!TYPES.include?(args[:updates_document_type])
|
27
|
+
warn "[relaton-iec] WARNING: invalid updates_document_type "\
|
28
|
+
"\"#{args[:updates_document_type]}\""
|
29
|
+
warn "[relaton-iec] allowed updates_document_type values are: "\
|
30
|
+
"#{TYPES.join(', ')}"
|
31
|
+
end
|
32
|
+
@function = args.delete :function
|
33
|
+
@updates_document_type = args.delete :updates_document_type
|
34
|
+
@accessibility_color_inside = args.delete :accessibility_color_inside
|
35
|
+
@price_code = args.delete :price_code
|
36
|
+
@cen_processing = args.delete :cen_processing
|
37
|
+
@secretary = args.delete :secretary
|
38
|
+
@interest_to_committees = args.delete :interest_to_committees
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param hash [Hash]
|
43
|
+
# @return [RelatonIsoBib::IecBibliographicItem]
|
44
|
+
def self.from_hash(hash)
|
45
|
+
item_hash = ::RelatonIec::HashConverter.hash_to_bib(hash)
|
46
|
+
new **item_hash
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param opts [Hash]
|
50
|
+
# @option opts [Nokogiri::XML::Builder] :builder XML builder
|
51
|
+
# @option opts [Boolean] :bibdata
|
52
|
+
# @option opts [String] :lang language
|
53
|
+
# @return [String] XML
|
54
|
+
def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
55
|
+
super **opts do |b|
|
56
|
+
if opts[:bibdata]
|
57
|
+
b.ext do
|
58
|
+
b.doctype doctype if doctype
|
59
|
+
b.horizontal horizontal unless horizontal.nil?
|
60
|
+
b.function function if function
|
61
|
+
editorialgroup&.to_xml b
|
62
|
+
ics.each { |i| i.to_xml b }
|
63
|
+
structuredidentifier&.to_xml b
|
64
|
+
b.stagename stagename if stagename
|
65
|
+
if updates_document_type
|
66
|
+
b.send("updates-document-type", updates_document_type)
|
67
|
+
end
|
68
|
+
unless accessibility_color_inside.nil?
|
69
|
+
b.send("accessibility-color-inside", accessibility_color_inside)
|
70
|
+
end
|
71
|
+
b.send("price-code", price_code) if price_code
|
72
|
+
b.send("cen-processing", cen_processing) unless cen_processing.nil?
|
73
|
+
b.secretary secretary if secretary
|
74
|
+
if interest_to_committees
|
75
|
+
b.send("interest-to-committees", interest_to_committees)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [Hash]
|
83
|
+
def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
84
|
+
hash = super
|
85
|
+
hash["function"] = function if function
|
86
|
+
if updates_document_type
|
87
|
+
hash["updates_document_type"] = updates_document_type
|
88
|
+
end
|
89
|
+
unless accessibility_color_inside.nil?
|
90
|
+
hash["accessibility_color_inside"] = accessibility_color_inside
|
91
|
+
end
|
92
|
+
hash["price_code"] = price_code if price_code
|
93
|
+
hash["cen_processing"] = cen_processing unless cen_processing.nil?
|
94
|
+
hash["secretary"] = secretary if secretary
|
95
|
+
if interest_to_committees
|
96
|
+
hash["interest_to_committees"] = interest_to_committees
|
97
|
+
end
|
98
|
+
hash
|
99
|
+
end
|
8
100
|
end
|
9
101
|
end
|
@@ -21,7 +21,7 @@ module RelatonIec
|
|
21
21
|
# @param part [String, nil] search for packaged stndard if not nil
|
22
22
|
# @return [RelatonIec::HitCollection]
|
23
23
|
def search(text, year = nil, part = nil)
|
24
|
-
HitCollection.new text, year&.strip, part
|
24
|
+
HitCollection.new text.sub(/(^\w+)\//, '\1 '), year&.strip, part
|
25
25
|
rescue SocketError, OpenURI::HTTPError, OpenSSL::SSL::SSLError
|
26
26
|
raise RelatonBib::RequestError, "Could not access http://www.iec.ch"
|
27
27
|
end
|
@@ -32,28 +32,29 @@ module RelatonIec
|
|
32
32
|
# reference is required
|
33
33
|
# @return [String] Relaton XML serialisation of reference
|
34
34
|
def get(code, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
35
|
+
opts[:all_parts] ||= code.match? /\s\(all parts\)/
|
36
|
+
ref = code.sub /\s\(all parts\)/, ""
|
35
37
|
if year.nil?
|
36
|
-
/^(?<code1>[^:]+):(?<year1>[^:]+)/ =~
|
38
|
+
/^(?<code1>[^:]+):(?<year1>[^:]+)/ =~ ref
|
37
39
|
unless code1.nil?
|
38
|
-
|
40
|
+
ref = code1
|
39
41
|
year = year1
|
40
42
|
end
|
41
43
|
end
|
44
|
+
return iev if ref.casecmp("IEV").zero?
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
opts[:all_parts] ||= !(code =~ / \(all parts\)/).nil?
|
46
|
-
code = code.sub(/ \(all parts\)/, "")
|
47
|
-
ret = iecbib_get1(code, year, opts)
|
46
|
+
ret = iecbib_get(ref, year, opts)
|
48
47
|
return nil if ret.nil?
|
49
48
|
|
50
49
|
ret = ret.to_most_recent_reference unless year || opts[:keep_year]
|
51
|
-
ret = ret.to_all_parts if opts[:all_parts]
|
52
50
|
ret
|
53
51
|
end
|
54
52
|
|
55
53
|
private
|
56
54
|
|
55
|
+
# @param code [String]
|
56
|
+
# @param year [String]
|
57
|
+
# @param missed_years [Array<String>]
|
57
58
|
def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
|
58
59
|
id = year ? "#{code}:#{year}" : code
|
59
60
|
warn "[relaton-iec] WARNING: no match found online for #{id}. "\
|
@@ -77,42 +78,43 @@ module RelatonIec
|
|
77
78
|
# @param hits [Array<RelatonIec::Hit>]
|
78
79
|
# @param threads [Integer]
|
79
80
|
# @return [Array<RelatonIec::Hit>]
|
80
|
-
def fetch_pages(hits, threads)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
|
81
|
+
# def fetch_pages(hits, threads)
|
82
|
+
# workers = RelatonBib::WorkersPool.new threads
|
83
|
+
# workers.worker { |w| { i: w[:i], hit: w[:hit].fetch } }
|
84
|
+
# hits.each_with_index { |hit, i| workers << { i: i, hit: hit } }
|
85
|
+
# workers.end
|
86
|
+
# workers.result.sort_by { |a| a[:i] }.map { |x| x[:hit] }
|
87
|
+
# end
|
88
|
+
|
89
|
+
# @param ref [String]
|
90
|
+
# @param year [String, nil]
|
91
|
+
# @return [RelatonIec::HitCollection]
|
92
|
+
def search_filter(ref, year) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
89
93
|
%r{
|
90
|
-
^(?<code
|
94
|
+
^(?<code>\S+[^\d]*\s\d+((?:-\w+)+)?)
|
91
95
|
(:(?<year1>\d{4}))?
|
92
96
|
(?<bundle>\+[^\s\/]+)?
|
93
97
|
(\/(?<corr>AMD\s\d+))?
|
94
|
-
}x =~
|
98
|
+
}x =~ ref.upcase
|
95
99
|
year ||= year1
|
96
100
|
corr&.sub! " ", ""
|
97
|
-
warn "[relaton-iec] (\"#{
|
101
|
+
warn "[relaton-iec] (\"#{ref}\") fetching..."
|
98
102
|
result = search(code, year)
|
99
|
-
if result.empty? && /(?<=-)(?<part
|
103
|
+
if result.empty? && /(?<=-)(?<part>[\w-]+)/ =~ code
|
100
104
|
# try to search packaged standard
|
101
105
|
result = search code, year, part
|
102
|
-
ref = code.sub /(?<=-\d)\d+/, ""
|
103
|
-
else ref = code
|
104
106
|
end
|
107
|
+
result = search code if result.empty?
|
108
|
+
code = result.text.dup
|
109
|
+
code&.sub! /((?:-\w+)+)/, ""
|
105
110
|
result.select do |i|
|
106
111
|
%r{
|
107
|
-
^(?<code2
|
108
|
-
(
|
112
|
+
^(?<code2>\S+[^\d]*\s\d+)((?:-\w+)+)?
|
113
|
+
(:\d{4})?
|
109
114
|
(?<bundle2>\+[^\s\/]+)?
|
110
115
|
(\/(?<corr2>AMD\d+))?
|
111
116
|
}x =~ i.hit[:code]
|
112
|
-
code2
|
113
|
-
code2.sub! /-\d+\w*/, "" if opts[:all_parts]
|
114
|
-
ref == code2 && (year.nil? || year == year2) && bundle == bundle2 &&
|
115
|
-
corr == corr2
|
117
|
+
code == code2 && bundle == bundle2 && corr == corr2
|
116
118
|
end
|
117
119
|
end
|
118
120
|
|
@@ -157,30 +159,61 @@ module RelatonIec
|
|
157
159
|
# Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
|
158
160
|
# If no match, returns any years which caused mismatch, for error
|
159
161
|
# reporting
|
160
|
-
def
|
162
|
+
def results_filter(result, year, opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
163
|
+
r_code, r_year = code_year result.text, result.part
|
164
|
+
r_year ||= year
|
161
165
|
missed_years = []
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
166
|
+
missed_parts = false
|
167
|
+
# result.each_slice(3) do |s| # ISO website only allows 3 connections
|
168
|
+
ret = if opts[:all_parts]
|
169
|
+
result.to_all_parts
|
170
|
+
else
|
171
|
+
result.detect do |h|
|
172
|
+
h_code, h_year = code_year h.hit[:code], result.part
|
173
|
+
missed_parts ||= !opts[:all_parts] && r_code != h_code
|
174
|
+
missed_years << h_year unless !r_year || h_year == r_year
|
175
|
+
r_code == h_code && (!year || h_year == r_year)
|
176
|
+
# fetch_pages(s, 3).each_with_index do |r, _i|
|
177
|
+
# return { ret: r } if !year
|
178
|
+
|
179
|
+
# r.date.select { |d| d.type == "published" }.each do |d|
|
180
|
+
# return { ret: r } if year.to_i == d.on(:year)
|
181
|
+
|
182
|
+
# missed_years << d.on(:year)
|
183
|
+
# end
|
184
|
+
# end
|
185
|
+
end&.fetch
|
186
|
+
end
|
187
|
+
{ ret: ret, years: missed_years, missed_parts: missed_parts }
|
174
188
|
end
|
175
189
|
|
176
|
-
|
177
|
-
|
190
|
+
# @param ref [String]
|
191
|
+
# @param part [String, nil]
|
192
|
+
# @return [Array<String, nil>]
|
193
|
+
def code_year(ref, part)
|
194
|
+
%r{
|
195
|
+
^(?<code>\S+[^\d]*\s\d+((?:-\w+)+)?)
|
196
|
+
(:(?<year>\d{4}))?
|
197
|
+
}x =~ ref
|
198
|
+
code.sub!(/-\d+/, "") if part
|
199
|
+
[code, year]
|
200
|
+
end
|
178
201
|
|
179
|
-
|
180
|
-
|
202
|
+
# @param code [String]
|
203
|
+
# @param year [String, nil]
|
204
|
+
# @param opts [Hash]
|
205
|
+
# @return [RelatonIec::IecBibliographicItem, nil]
|
206
|
+
def iecbib_get(code, year, opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
207
|
+
result = search_filter(code, year) || return
|
208
|
+
ret = results_filter(result, year, opts)
|
181
209
|
if ret[:ret]
|
182
|
-
|
183
|
-
|
210
|
+
if ret[:missed_parts]
|
211
|
+
warn "[relaton-iec] WARNING: #{code} found as #{ret[:ret].docidentifier.first.id} "\
|
212
|
+
"but also contain parts. If you wanted to cite all document parts for the reference, use "\
|
213
|
+
"\"#{code} (all parts)\""
|
214
|
+
else
|
215
|
+
warn "[relaton-iec] (\"#{code}\") found #{ret[:ret].docidentifier.first.id}"
|
216
|
+
end
|
184
217
|
ret[:ret]
|
185
218
|
else
|
186
219
|
fetch_ref_err(code, year, ret[:years])
|
@@ -26,8 +26,7 @@ module RelatonIec
|
|
26
26
|
# @param hash [Hash]
|
27
27
|
# @return [RelatonIsoBib::IecBibliographicItem]
|
28
28
|
def hash_to_bib(hash)
|
29
|
-
|
30
|
-
::RelatonIec::IecBibliographicItem.new item_hash
|
29
|
+
::RelatonIec::IecBibliographicItem.from_hash hash
|
31
30
|
end
|
32
31
|
|
33
32
|
# Returns hash of XML grammar
|
@@ -35,5 +34,11 @@ module RelatonIec
|
|
35
34
|
def grammar_hash
|
36
35
|
@grammar_hash ||= ::RelatonIec.grammar_hash
|
37
36
|
end
|
37
|
+
|
38
|
+
# @param code [String]
|
39
|
+
# @return [String, nil]
|
40
|
+
def urn_to_code(code)
|
41
|
+
RelatonIec.urn_to_code code
|
42
|
+
end
|
38
43
|
end
|
39
44
|
end
|
data/lib/relaton_iec/scrapper.rb
CHANGED
@@ -69,38 +69,13 @@ module RelatonIec
|
|
69
69
|
# @param hit [Hash]
|
70
70
|
# @return [Array<RelatonBib::DocumentIdentifier>]
|
71
71
|
def fetch_docid(hit)
|
72
|
-
|
73
|
-
(?<head>[^\s]+)\s
|
74
|
-
(?<type>is|ts|tr|pas|srd|guide|tec|wp)?(?(<type>)\s)
|
75
|
-
(?<pnum>[\d-]+)\s?
|
76
|
-
(?<_dd>:)?(?(<_dd>)(?<date>[\d-]+)\s?)
|
77
|
-
}x, "")
|
78
|
-
m = $~
|
79
|
-
deliv = /cmv|csv|exv|prv|rlv|ser/.match(hit[:code].downcase).to_s
|
80
|
-
urn = ["urn", "iec", "std", m[:head].split("/").join("-"), m[:pnum],
|
81
|
-
m[:date], m[:type], deliv, "en"]
|
82
|
-
urn += fetch_ajunct(rest)
|
72
|
+
urn = RelatonIec.code_to_urn hit[:code], "en"
|
83
73
|
[
|
84
74
|
RelatonBib::DocumentIdentifier.new(id: hit[:code], type: "IEC"),
|
85
|
-
RelatonBib::DocumentIdentifier.new(id: urn
|
75
|
+
RelatonBib::DocumentIdentifier.new(id: urn, type: "URN"),
|
86
76
|
]
|
87
77
|
end
|
88
78
|
|
89
|
-
# @param rest [String]
|
90
|
-
# @return [Array<String, nil>]
|
91
|
-
def fetch_ajunct(rest)
|
92
|
-
r = rest.sub(%r{
|
93
|
-
(?<_pl>\+)(?(<_pl>)(?<adjunct>amd)(?<adjnum>\d+)\s?)
|
94
|
-
(?<_d2>:)?(?(<_d2>)(?<adjdt>[\d-]+)\s?)
|
95
|
-
}x, "")
|
96
|
-
m = $~ || {}
|
97
|
-
return [] unless m[:adjunct]
|
98
|
-
|
99
|
-
plus = m[:adjunct] && "plus"
|
100
|
-
urn = [plus, m[:adjunct], m[:adjnum], m[:adjdt]]
|
101
|
-
urn + fetch_ajunct(r)
|
102
|
-
end
|
103
|
-
|
104
79
|
# Fetch abstracts.
|
105
80
|
# @param doc [Nokigiri::HTML::Document]
|
106
81
|
# @return [Array<Array>]
|
@@ -266,14 +241,7 @@ module RelatonIec
|
|
266
241
|
|
267
242
|
def fetch_contributors(code)
|
268
243
|
code.sub(/\s.*/, "").split("/").map do |abbrev|
|
269
|
-
|
270
|
-
when "ISO"
|
271
|
-
name = "International Organization for Standardization"
|
272
|
-
url = "www.iso.org"
|
273
|
-
when "IEC"
|
274
|
-
name = "International Electrotechnical Commission"
|
275
|
-
url = "www.iec.ch"
|
276
|
-
end
|
244
|
+
name, url = name_url abbrev
|
277
245
|
{ entity: { name: name, url: url, abbreviation: abbrev },
|
278
246
|
role: [type: "publisher"] }
|
279
247
|
end
|
@@ -310,11 +278,7 @@ module RelatonIec
|
|
310
278
|
# @return [Array<Hash>]
|
311
279
|
def fetch_copyright(code, doc)
|
312
280
|
abbreviation = code.match(/.*?(?=\s)/).to_s
|
313
|
-
|
314
|
-
when "IEC"
|
315
|
-
name = "International Electrotechnical Commission"
|
316
|
-
url = "www.iec.ch"
|
317
|
-
end
|
281
|
+
name, url = name_url abbreviation
|
318
282
|
from = code.match(/(?<=:)\d{4}/).to_s
|
319
283
|
if from.empty?
|
320
284
|
from = doc.xpath("//span[@itemprop='releaseDate']").text
|
@@ -326,6 +290,14 @@ module RelatonIec
|
|
326
290
|
}]
|
327
291
|
end
|
328
292
|
# rubocop:enable Metrics/MethodLength
|
293
|
+
|
294
|
+
def name_url(abbrev)
|
295
|
+
case abbrev
|
296
|
+
when "ISO" then ["International Organization for Standardization", "www.iso.org"]
|
297
|
+
when "IEC" then ["International Electrotechnical Commission", "www.iec.ch"]
|
298
|
+
when "CISPR" then ["International special committee on radio interference", "www.iec.ch"]
|
299
|
+
end
|
300
|
+
end
|
329
301
|
end
|
330
302
|
end
|
331
303
|
end
|