relaton-iso 1.11.1 → 1.12.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 +1 -24
- data/lib/relaton_iso/document_identifier.rb +28 -0
- data/lib/relaton_iso/hit.rb +8 -3
- data/lib/relaton_iso/hit_collection.rb +4 -8
- data/lib/relaton_iso/iso_bibliography.rb +97 -127
- data/lib/relaton_iso/scrapper.rb +18 -41
- data/lib/relaton_iso/version.rb +1 -1
- data/lib/relaton_iso.rb +2 -0
- data/relaton_iso.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: 3600bb96dbe0079a7a3decb1ed1e72d4bf8b0b1b3e3dbf895ce09babea1180e8
|
4
|
+
data.tar.gz: d01275c03e71b7bcc0137c3b72035cd19894eb39812d70f1ddadbb1e2c0354c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e6d8c80fef320926e2c3fd71be2963e8d68216ee26079640495a610af32efce41fba270929a61bb989d8ddae1bc04bcf168428782e1e9d51643ca1ed49b59c1
|
7
|
+
data.tar.gz: 5d26dd354ca5d1cc6eeaac3ae612343ec63aa79fa5b584720490f7f0780937e47396cabf1fb0e4b2822161a9f7baad27df7c9bd4e9789bbb7387b3e91f80fc52
|
data/.github/workflows/rake.yml
CHANGED
@@ -10,27 +10,4 @@ on:
|
|
10
10
|
|
11
11
|
jobs:
|
12
12
|
rake:
|
13
|
-
|
14
|
-
runs-on: ${{ matrix.os }}
|
15
|
-
continue-on-error: ${{ matrix.experimental }}
|
16
|
-
strategy:
|
17
|
-
fail-fast: false
|
18
|
-
matrix:
|
19
|
-
ruby: [ '3.0', '2.7', '2.6', '2.5' ]
|
20
|
-
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
|
-
experimental: [ false ]
|
22
|
-
steps:
|
23
|
-
- uses: actions/checkout@v2
|
24
|
-
with:
|
25
|
-
submodules: true
|
26
|
-
|
27
|
-
# https://github.com/ruby-debug/debase/issues/89#issuecomment-686827382
|
28
|
-
- if: matrix.os == 'macos-latest' && matrix.ruby == '2.5'
|
29
|
-
run: echo BUNDLE_BUILD__DEBASE="--with-cflags=\"-Wno-error=implicit-function-declaration\"" >> $GITHUB_ENV
|
30
|
-
|
31
|
-
- uses: ruby/setup-ruby@v1
|
32
|
-
with:
|
33
|
-
ruby-version: ${{ matrix.ruby }}
|
34
|
-
bundler-cache: true
|
35
|
-
|
36
|
-
- run: bundle exec rake
|
13
|
+
uses: relaton/support/.github/workflows/rake.yml@master
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RelatonIso
|
2
|
+
class DocumentIdentifier < RelatonBib::DocumentIdentifier
|
3
|
+
attr_accessor :all_parts
|
4
|
+
|
5
|
+
def id
|
6
|
+
if @all_parts
|
7
|
+
if type == "URN"
|
8
|
+
return "#{@id.urn}:ser"
|
9
|
+
else
|
10
|
+
return "#{@id} (all parts)"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
type == "URN" ? @id.urn.to_s : @id.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def remove_part
|
17
|
+
@id.part = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove_date
|
21
|
+
@id.year = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def all_parts
|
25
|
+
@all_parts = true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/relaton_iso/hit.rb
CHANGED
@@ -4,13 +4,13 @@ module RelatonIso
|
|
4
4
|
# Hit.
|
5
5
|
class Hit < RelatonBib::Hit
|
6
6
|
# @return [RelatonIsoBib::IsoBibliographicItem]
|
7
|
-
attr_writer :fetch
|
7
|
+
attr_writer :fetch, :pubid
|
8
8
|
|
9
9
|
# Parse page.
|
10
10
|
# @param lang [String, NilClass]
|
11
11
|
# @return [RelatonIso::IsoBibliographicItem]
|
12
|
-
def fetch(lang = nil)
|
13
|
-
@fetch ||= Scrapper.parse_page @hit, lang
|
12
|
+
def fetch(lang = nil, all_parts = false)
|
13
|
+
@fetch ||= Scrapper.parse_page @hit, lang, all_parts
|
14
14
|
end
|
15
15
|
|
16
16
|
# @return [Integer]
|
@@ -23,5 +23,10 @@ module RelatonIso
|
|
23
23
|
else 4
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
# @return [Pubid::Iso::Identifier]
|
28
|
+
def pubid
|
29
|
+
Pubid::Iso::Identifier.parse_from_title(hit[:title])
|
30
|
+
end
|
26
31
|
end
|
27
32
|
end
|
@@ -11,25 +11,21 @@ module RelatonIso
|
|
11
11
|
# @param text [String] reference to search
|
12
12
|
def initialize(text)
|
13
13
|
super
|
14
|
-
@array = text.match?(/^ISO\
|
14
|
+
@array = text.match?(/^ISO\s(?:TC\s184\/SC\s?4|IEC\sDIR\s(?:\d|IEC|JTC))/) ? fetch_github : fetch_iso
|
15
15
|
end
|
16
16
|
|
17
17
|
# @param lang [String, NilClass]
|
18
18
|
# @return [RelatonIsoBib::IsoBibliographicItem]
|
19
19
|
def to_all_parts(lang = nil) # rubocop:disable Metrics/CyclomaticComplexity
|
20
20
|
# parts = @array.reject { |h| h.hit["docPart"]&.empty? }
|
21
|
-
hit = @array.min_by
|
22
|
-
IsoBibliography.ref_components(h.hit[:title])[1].to_i
|
23
|
-
end
|
21
|
+
hit = @array.min_by { |h| h.pubid.part }
|
24
22
|
return @array.first.fetch lang unless hit
|
25
23
|
|
26
|
-
bibitem = hit.fetch
|
24
|
+
bibitem = hit.fetch(lang, true)
|
27
25
|
all_parts_item = bibitem.to_all_parts
|
28
26
|
@array.reject { |h| h.hit[:uuid] == hit.hit[:uuid] }.each do |hi|
|
29
|
-
%r{^(?<fr>ISO(?:\s|/)[^-/:()]+(?:-[\w-]+)?(?::\d{4})?
|
30
|
-
(?:/\w+(?:\s\w+)?\s\d+(?:\d{4})?)?)}x =~ hi.hit[:title]
|
31
27
|
isobib = RelatonIsoBib::IsoBibliographicItem.new(
|
32
|
-
formattedref: RelatonBib::FormattedRef.new(content:
|
28
|
+
formattedref: RelatonBib::FormattedRef.new(content: hi.pubid.to_s),
|
33
29
|
)
|
34
30
|
all_parts_item.relation << RelatonBib::DocumentRelation.new(
|
35
31
|
type: "instance", bibitem: isobib,
|
@@ -27,57 +27,97 @@ module RelatonIso
|
|
27
27
|
# @option opts [Boolean] :keep_year if undated reference should return
|
28
28
|
# actual reference with year
|
29
29
|
#
|
30
|
-
# @return [
|
30
|
+
# @return [RelatonIsoBib::IsoBibliographicItem] Relaton XML serialisation of reference
|
31
31
|
def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/AbcSize
|
32
32
|
code = ref.gsub(/\u2013/, "-")
|
33
|
-
|
34
|
-
|
33
|
+
|
34
|
+
# parse "all parts" request
|
35
35
|
code.sub! " (all parts)", ""
|
36
36
|
opts[:all_parts] ||= $~ && opts[:all_parts].nil?
|
37
|
-
# opts[:keep_year] ||= opts[:keep_year].nil?
|
38
|
-
# code.sub!("#{num}-#{part}", num) if opts[:all_parts] && part
|
39
|
-
# if %r[^ISO/IEC DIR].match? code
|
40
|
-
# return RelatonIec::IecBibliography.get(code, year, opts)
|
41
|
-
# end
|
42
37
|
|
43
|
-
|
44
|
-
|
38
|
+
query_pubid = Pubid::Iso::Identifier.parse(code)
|
39
|
+
query_pubid.year = year if year
|
40
|
+
|
41
|
+
hits = isobib_search_filter(query_pubid, opts)
|
45
42
|
|
46
|
-
|
43
|
+
# return only first one if not all_parts
|
44
|
+
ret = if !opts[:all_parts] || hits.size == 1
|
45
|
+
hits.any? && hits.first.fetch(opts[:lang])
|
46
|
+
else
|
47
|
+
hits.to_all_parts(opts[:lang])
|
48
|
+
end
|
49
|
+
|
50
|
+
if ret
|
51
|
+
warn "[relaton-iso] (\"#{query_pubid}\") found #{ret.docidentifier.first.id}"
|
52
|
+
else
|
53
|
+
return fetch_ref_err(query_pubid, query_pubid.year)
|
54
|
+
end
|
55
|
+
|
56
|
+
if (query_pubid.year && opts[:keep_year].nil?) || opts[:keep_year] || opts[:all_parts]
|
47
57
|
ret
|
48
58
|
else
|
49
59
|
ret.to_most_recent_reference
|
50
60
|
end
|
51
61
|
end
|
52
62
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
# @param query_pubid [Pubid::Iso::Identifier]
|
64
|
+
# @param pubid [Pubid::Iso::Identifier]
|
65
|
+
# @param all_parts [Boolean] match with any parts when true
|
66
|
+
# @return [Boolean]
|
67
|
+
def matches_parts?(query_pubid, pubid, all_parts: false)
|
68
|
+
if all_parts
|
69
|
+
# match only with documents with part number
|
70
|
+
!pubid.part.nil?
|
71
|
+
else
|
72
|
+
query_pubid.part == pubid.part
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def matches_base?(query_pubid, pubid, any_types_stages: false)
|
77
|
+
query_pubid.publisher == pubid.publisher &&
|
78
|
+
query_pubid.number == pubid.number &&
|
79
|
+
query_pubid.copublisher == pubid.copublisher &&
|
80
|
+
(any_types_stages && query_pubid.stage.nil? || query_pubid.stage == pubid.stage) &&
|
81
|
+
(any_types_stages && query_pubid.type.nil? || query_pubid.type == pubid.type)
|
82
|
+
end
|
83
|
+
|
84
|
+
# @param hit_collection [RelatonIso::HitCollection]
|
85
|
+
# @param year [String]
|
86
|
+
# @return [RelatonIso::HitCollection]
|
87
|
+
def filter_hits_by_year(hit_collection, year)
|
88
|
+
missed_years = []
|
89
|
+
|
90
|
+
# filter by year
|
91
|
+
hits = hit_collection.select do |hit|
|
92
|
+
if hit.pubid.year == year
|
93
|
+
true
|
94
|
+
else
|
95
|
+
missed_years << hit.pubid.year
|
96
|
+
false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
if hits.empty? && !missed_years.empty?
|
101
|
+
warn "[relaton-iso] (There was no match for #{year}, though there "\
|
102
|
+
"were matches found for #{missed_years.join(', ')}.)"
|
103
|
+
end
|
104
|
+
hits
|
61
105
|
end
|
62
106
|
|
63
107
|
private
|
64
108
|
|
65
109
|
# rubocop:disable Metrics/MethodLength
|
66
110
|
|
67
|
-
def fetch_ref_err(
|
68
|
-
id = year ? "#{
|
111
|
+
def fetch_ref_err(query_pubid, year)
|
112
|
+
id = year ? "#{query_pubid}:#{year}" : query_pubid
|
69
113
|
warn "[relaton-iso] WARNING: no match found online for #{id}. "\
|
70
114
|
"The code must be exactly like it is on the standards website."
|
71
|
-
|
72
|
-
warn "[relaton-iso] (There was no match for #{year}, though there "\
|
73
|
-
"were matches found for #{missed_years.join(', ')}.)"
|
74
|
-
end
|
75
|
-
if /\d-\d/.match? code
|
115
|
+
if /\d-\d/.match? query_pubid.to_s
|
76
116
|
warn "[relaton-iso] The provided document part may not exist, "\
|
77
117
|
"or the document may no longer be published in parts."
|
78
118
|
else
|
79
119
|
warn "[relaton-iso] If you wanted to cite all document parts for "\
|
80
|
-
"the reference, use \"#{
|
120
|
+
"the reference, use \"#{query_pubid} (all parts)\".\nIf the document "\
|
81
121
|
"is not a standard, use its document type abbreviation "\
|
82
122
|
"(TS, TR, PAS, Guide)."
|
83
123
|
end
|
@@ -88,119 +128,49 @@ module RelatonIso
|
|
88
128
|
|
89
129
|
# Search for hits. If no found then trying missed stages and ISO/IEC.
|
90
130
|
#
|
91
|
-
# @param
|
131
|
+
# @param query_pubid [Pubid::Iso::Identifier] reference without correction
|
92
132
|
# @param opts [Hash]
|
93
133
|
# @return [Array<RelatonIso::Hit>]
|
94
|
-
def isobib_search_filter(
|
95
|
-
|
96
|
-
warn "[relaton-iso] (\"#{
|
97
|
-
|
98
|
-
|
134
|
+
def isobib_search_filter(query_pubid, opts)
|
135
|
+
query_pubid.part = nil if opts[:all_parts]
|
136
|
+
warn "[relaton-iso] (\"#{query_pubid}\") fetching..."
|
137
|
+
# fetch hits collection
|
138
|
+
hit_collection = search(query_pubid.to_s(with_date: false))
|
139
|
+
# filter only matching hits
|
140
|
+
res = filter_hits hit_collection, query_pubid,
|
141
|
+
all_parts: opts[:all_parts]
|
99
142
|
return res unless res.empty?
|
100
143
|
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
code.sub(%r{^(?<pref>[^\s]+\s)}) { "#{$~[:pref]}#{st} " }
|
106
|
-
end
|
107
|
-
return res unless res.empty?
|
108
|
-
when %r{^\w+\s\d+} # code like ISO 123
|
109
|
-
res = try_stages(result, opts) do |st|
|
110
|
-
code.sub(%r{^(?<pref>\w+)}) { "#{$~[:pref]}/#{st}" }
|
111
|
-
end
|
112
|
-
return res unless res.empty?
|
113
|
-
end
|
144
|
+
# lookup for documents with stages when no match without stage
|
145
|
+
res = filter_hits hit_collection, query_pubid,
|
146
|
+
all_parts: opts[:all_parts], any_types_stages: true
|
147
|
+
return res unless res.empty?
|
114
148
|
|
115
|
-
|
149
|
+
# TODO: do this at pubid-iso
|
150
|
+
if query_pubid.publisher == "ISO" && query_pubid.copublisher.nil? # try ISO/IEC if ISO not found
|
116
151
|
warn "[relaton-iso] Attempting ISO/IEC retrieval"
|
117
|
-
|
118
|
-
res =
|
119
|
-
end
|
120
|
-
res
|
121
|
-
end
|
122
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
123
|
-
|
124
|
-
def remove_part(ref, all_parts)
|
125
|
-
return ref unless all_parts
|
126
|
-
|
127
|
-
ref.sub %r{(\S+\s\d+)[\d-]+}, '\1'
|
128
|
-
end
|
129
|
-
|
130
|
-
# @param result [RelatonIso::HitCollection]
|
131
|
-
# @param opts [Hash]
|
132
|
-
# @return [RelatonIso::HitCollection]
|
133
|
-
def try_stages(result, opts)
|
134
|
-
res = nil
|
135
|
-
%w[NP WD CD DIS FDIS PRF IS AWI TR].each do |st| # try stages
|
136
|
-
c = yield st
|
137
|
-
res = search_code result, c, opts
|
138
|
-
return res unless res.empty?
|
152
|
+
query_pubid.copublisher = "IEC"
|
153
|
+
res = filter_hits hit_collection, query_pubid, all_parts: opts[:all_parts]
|
139
154
|
end
|
140
155
|
res
|
141
156
|
end
|
142
157
|
|
143
|
-
# @param
|
144
|
-
# @param
|
145
|
-
# @param
|
158
|
+
# @param hits [RelatonIso::HitCollection]
|
159
|
+
# @param query_pubid [Pubid::Iso::Identifier]
|
160
|
+
# @param all_parts [Boolean]
|
161
|
+
# @param any_stages [Boolean]
|
146
162
|
# @return [RelatonIso::HitCollection]
|
147
|
-
def
|
148
|
-
|
149
|
-
result.select do |i|
|
150
|
-
|
151
|
-
|
152
|
-
|
163
|
+
def filter_hits(hit_collection, query_pubid, all_parts: false, any_types_stages: false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
164
|
+
# filter out
|
165
|
+
result = hit_collection.select do |i|
|
166
|
+
hit_pubid = i.pubid
|
167
|
+
matches_base?(query_pubid, hit_pubid, any_types_stages: any_types_stages) &&
|
168
|
+
matches_parts?(query_pubid, hit_pubid, all_parts: all_parts) &&
|
169
|
+
query_pubid.corrigendum == hit_pubid.corrigendum &&
|
170
|
+
query_pubid.amendment == hit_pubid.amendment
|
153
171
|
end
|
154
|
-
end
|
155
|
-
|
156
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
157
172
|
|
158
|
-
|
159
|
-
# and return the first result that matches the code, matches the year
|
160
|
-
# (if provided), and which # has a title (amendments do not).
|
161
|
-
# Only expects the first page of results to be populated.
|
162
|
-
# Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
|
163
|
-
# If no match, returns any years which caused mismatch, for error
|
164
|
-
# reporting
|
165
|
-
def isobib_results_filter(result, year, opts)
|
166
|
-
missed_years = []
|
167
|
-
hits = result.reduce!([]) do |hts, h|
|
168
|
-
iyear = publish_year h.hit[:title]
|
169
|
-
if !year || iyear == year
|
170
|
-
hts << h
|
171
|
-
else
|
172
|
-
missed_years << iyear
|
173
|
-
hts
|
174
|
-
end
|
175
|
-
end
|
176
|
-
return { years: missed_years } unless hits.any?
|
177
|
-
|
178
|
-
if !opts[:all_parts] || hits.size == 1
|
179
|
-
return { ret: hits.first.fetch(opts[:lang]) }
|
180
|
-
end
|
181
|
-
|
182
|
-
{ ret: hits.to_all_parts(opts[:lang]) }
|
183
|
-
end
|
184
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
185
|
-
|
186
|
-
def publish_year(ref)
|
187
|
-
%r{:(?<year>\d{4})(?!.*:\d{4})} =~ ref
|
188
|
-
year
|
189
|
-
end
|
190
|
-
|
191
|
-
# @param code [String]
|
192
|
-
# @param year [String, NilClass]
|
193
|
-
# @param opts [Hash]
|
194
|
-
def isobib_get(code, year, opts)
|
195
|
-
# return iev(code) if /^IEC 60050-/.match code
|
196
|
-
result = isobib_search_filter(code, opts) || return
|
197
|
-
ret = isobib_results_filter(result, year, opts)
|
198
|
-
if ret[:ret]
|
199
|
-
warn "[relaton-iso] (\"#{code}\") found #{ret[:ret].docidentifier.first.id}"
|
200
|
-
ret[:ret]
|
201
|
-
else
|
202
|
-
fetch_ref_err(code, year, ret[:years])
|
203
|
-
end
|
173
|
+
query_pubid.year ? filter_hits_by_year(result, query_pubid.year) : result
|
204
174
|
end
|
205
175
|
end
|
206
176
|
end
|
data/lib/relaton_iso/scrapper.rb
CHANGED
@@ -52,10 +52,11 @@ module RelatonIso
|
|
52
52
|
# Parse page.
|
53
53
|
# @param hit_data [Hash]
|
54
54
|
# @param lang [String, NilClass]
|
55
|
-
# @return [
|
56
|
-
def parse_page(hit_data, lang = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
55
|
+
# @return [RelatonIsoBib::IsoBibliographicItem]
|
56
|
+
def parse_page(hit_data, lang = nil, all_parts = false) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
57
57
|
# path = "/contents/data/standard#{hit_data['splitPath']}/"\
|
58
58
|
# "#{hit_data['csnumber']}.html"
|
59
|
+
|
59
60
|
doc, url = get_page "#{hit_data[:path].sub '/sites/isoorg', ''}.html"
|
60
61
|
|
61
62
|
# Fetch edition.
|
@@ -66,7 +67,7 @@ module RelatonIso
|
|
66
67
|
|
67
68
|
RelatonIsoBib::IsoBibliographicItem.new(
|
68
69
|
fetched: Date.today.to_s,
|
69
|
-
docid:
|
70
|
+
docid: fetch_relaton_docids(Pubid::Iso::Identifier.parse(item_ref(doc))),
|
70
71
|
docnumber: fetch_docnumber(doc),
|
71
72
|
edition: edition,
|
72
73
|
language: langs.map { |l| l[:lang] },
|
@@ -87,6 +88,20 @@ module RelatonIso
|
|
87
88
|
)
|
88
89
|
end
|
89
90
|
|
91
|
+
# Fetch relaton docids.
|
92
|
+
# @param pubid [Pubid::Iso::Identifier]
|
93
|
+
# @param edition [String]
|
94
|
+
# @param langs [Array<Hash>]
|
95
|
+
# @param stage [Float]
|
96
|
+
# @return [Array<RelatonBib::DocumentIdentifier>]
|
97
|
+
def fetch_relaton_docids(pubid)
|
98
|
+
pubid.urn_stage = 60.60
|
99
|
+
[
|
100
|
+
RelatonIso::DocumentIdentifier.new(id: pubid, type: "ISO", primary: true),
|
101
|
+
RelatonIso::DocumentIdentifier.new(id: pubid, type: "URN"),
|
102
|
+
]
|
103
|
+
end
|
104
|
+
|
90
105
|
private
|
91
106
|
|
92
107
|
# Fetch titles and abstracts.
|
@@ -168,44 +183,6 @@ module RelatonIso
|
|
168
183
|
end
|
169
184
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
170
185
|
|
171
|
-
# Fetch docid.
|
172
|
-
# @param doc [Nokogiri:HTML::Document]
|
173
|
-
# @param edition [String]
|
174
|
-
# @param langs [Array<Hash>]
|
175
|
-
# @return [Array<RelatonBib::DocumentIdentifier>]
|
176
|
-
def fetch_docid(doc, edition, langs)
|
177
|
-
pubid = item_ref doc
|
178
|
-
[
|
179
|
-
RelatonBib::DocumentIdentifier.new(id: pubid, type: "ISO", primary: true),
|
180
|
-
RelatonBib::DocumentIdentifier.new(
|
181
|
-
id: fetch_urn(doc, pubid, edition, langs), type: "URN",
|
182
|
-
),
|
183
|
-
]
|
184
|
-
end
|
185
|
-
|
186
|
-
# @param doc [Nokogiri:HTML::Document]
|
187
|
-
# @param pubid [String]
|
188
|
-
# @param edition [String]
|
189
|
-
# @param langs [Array<Hash>]
|
190
|
-
# @returnt [String]
|
191
|
-
def fetch_urn(doc, pubid, edition, langs) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
|
192
|
-
orig = pubid.split.first.downcase.split("/").join "-"
|
193
|
-
%r{(?<=)(?<type>DATA|GUIDE|ISP|IWA|PAS|R|TR|TS|TTA)} =~ pubid
|
194
|
-
_, part, _year, corr, = IsoBibliography.ref_components pubid
|
195
|
-
urn = "urn:iso:std:#{orig}"
|
196
|
-
urn += ":#{type.downcase}" if type
|
197
|
-
urn += ":#{fetch_docnumber(doc)}"
|
198
|
-
urn += ":-#{part}" if part
|
199
|
-
urn += ":stage-#{stage_code(doc)}"
|
200
|
-
urn += ":ed-#{edition}" if edition
|
201
|
-
if corr
|
202
|
-
corrparts = corr.split
|
203
|
-
urn += ":#{corrparts[0].downcase}:#{corrparts[-1]}"
|
204
|
-
end
|
205
|
-
urn += ":#{langs.map { |l| l[:lang] }.join(',')}"
|
206
|
-
urn
|
207
|
-
end
|
208
|
-
|
209
186
|
def fetch_docnumber(doc)
|
210
187
|
item_ref(doc)&.match(/\d+/)&.to_s
|
211
188
|
end
|
data/lib/relaton_iso/version.rb
CHANGED
data/lib/relaton_iso.rb
CHANGED
data/relaton_iso.gemspec
CHANGED
@@ -42,5 +42,6 @@ Gem::Specification.new do |spec|
|
|
42
42
|
|
43
43
|
# spec.add_dependency "relaton-iec", "~> 1.8.0"
|
44
44
|
spec.add_dependency "algolia"
|
45
|
-
spec.add_dependency "relaton-iso-bib", "~> 1.
|
45
|
+
spec.add_dependency "relaton-iso-bib", "~> 1.12.0"
|
46
|
+
spec.add_dependency "pubid-iso", "~> 0.1.7"
|
46
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-iso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -184,14 +184,28 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: 1.
|
187
|
+
version: 1.12.0
|
188
188
|
type: :runtime
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: 1.
|
194
|
+
version: 1.12.0
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: pubid-iso
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 0.1.7
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 0.1.7
|
195
209
|
description: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
|
196
210
|
model'
|
197
211
|
email:
|
@@ -231,6 +245,7 @@ files:
|
|
231
245
|
- bin/safe_yaml
|
232
246
|
- bin/setup
|
233
247
|
- lib/relaton_iso.rb
|
248
|
+
- lib/relaton_iso/document_identifier.rb
|
234
249
|
- lib/relaton_iso/hit.rb
|
235
250
|
- lib/relaton_iso/hit_collection.rb
|
236
251
|
- lib/relaton_iso/iso_bibliography.rb
|