relaton-bib 1.4.0 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/integration-tests.yml +54 -0
- data/.github/workflows/rake.yml +15 -0
- data/.github/workflows/release.yml +24 -0
- data/.gitignore +4 -1
- data/.rubocop.yml +3 -1
- data/CLAUDE.md +108 -0
- data/Gemfile +11 -0
- data/README.adoc +229 -314
- data/bin/console +1 -1
- data/docs/hash.adoc +132 -83
- data/lib/relaton/bib/converter/asciibib/to_asciibib.rb +663 -0
- data/lib/relaton/bib/converter/asciibib.rb +13 -0
- data/lib/relaton/bib/converter/bibtex/from_bibtex.rb +245 -0
- data/lib/relaton/bib/converter/bibtex/to_bibtex.rb +341 -0
- data/lib/relaton/bib/converter/bibtex.rb +23 -0
- data/lib/relaton/bib/converter/bibxml/from_rfcxml.rb +386 -0
- data/lib/relaton/bib/converter/bibxml/from_rfcxml_referencegroup.rb +71 -0
- data/lib/relaton/bib/converter/bibxml/to_rfcxml.rb +308 -0
- data/lib/relaton/bib/converter/bibxml/to_rfcxml_referencegroup.rb +52 -0
- data/lib/relaton/bib/converter/bibxml.rb +51 -0
- data/lib/relaton/bib/hash_parser_v1.rb +767 -0
- data/lib/relaton/bib/item_data.rb +229 -0
- data/lib/relaton/bib/model/abstract.rb +16 -0
- data/lib/relaton/bib/model/address.rb +22 -0
- data/lib/relaton/bib/model/affiliation.rb +16 -0
- data/lib/relaton/bib/model/bibdata.rb +9 -0
- data/lib/relaton/bib/model/bibdata_shared.rb +10 -0
- data/lib/relaton/bib/model/bibitem.rb +9 -0
- data/lib/relaton/bib/model/bibitem_shared.rb +10 -0
- data/lib/relaton/bib/model/contact.rb +14 -0
- data/lib/relaton/bib/model/contribution_info.rb +16 -0
- data/lib/relaton/bib/model/contributor.rb +29 -0
- data/lib/relaton/bib/model/copyright.rb +27 -0
- data/lib/relaton/bib/model/date.rb +29 -0
- data/lib/relaton/bib/model/depiction.rb +16 -0
- data/lib/relaton/bib/model/docidentifier.rb +34 -0
- data/lib/relaton/bib/model/doctype.rb +14 -0
- data/lib/relaton/bib/model/edition.rb +14 -0
- data/lib/relaton/bib/model/ext.rb +35 -0
- data/lib/relaton/bib/model/extent.rb +16 -0
- data/lib/relaton/bib/model/formattedref.rb +43 -0
- data/lib/relaton/bib/model/full_name_type.rb +64 -0
- data/lib/relaton/bib/model/fullname.rb +11 -0
- data/lib/relaton/bib/model/ics.rb +49 -0
- data/lib/relaton/bib/model/image.rb +28 -0
- data/lib/relaton/bib/model/item.rb +44 -0
- data/lib/relaton/bib/model/item_base.rb +20 -0
- data/lib/relaton/bib/model/item_shared.rb +88 -0
- data/lib/relaton/bib/model/keyword.rb +30 -0
- data/lib/relaton/bib/model/locality.rb +18 -0
- data/lib/relaton/bib/model/locality_stack.rb +14 -0
- data/lib/relaton/bib/model/localized_string.rb +48 -0
- data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
- data/lib/relaton/bib/model/logo.rb +14 -0
- data/lib/relaton/bib/model/medium.rb +22 -0
- data/lib/relaton/bib/model/note.rb +16 -0
- data/lib/relaton/bib/model/organization.rb +11 -0
- data/lib/relaton/bib/model/organization_type.rb +40 -0
- data/lib/relaton/bib/model/person.rb +36 -0
- data/lib/relaton/bib/model/phone.rb +14 -0
- data/lib/relaton/bib/model/place.rb +33 -0
- data/lib/relaton/bib/model/price.rb +14 -0
- data/lib/relaton/bib/model/relation.rb +41 -0
- data/lib/relaton/bib/model/series.rb +32 -0
- data/lib/relaton/bib/model/size.rb +23 -0
- data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
- data/lib/relaton/bib/model/status.rb +27 -0
- data/lib/relaton/bib/model/structured_identifier.rb +48 -0
- data/lib/relaton/bib/model/subdivision.rb +16 -0
- data/lib/relaton/bib/model/title.rb +56 -0
- data/lib/relaton/bib/model/type/plain_date.rb +16 -0
- data/lib/relaton/bib/model/type/string_date.rb +48 -0
- data/lib/relaton/bib/model/uri.rb +18 -0
- data/lib/relaton/bib/model/validity.rb +16 -0
- data/lib/relaton/bib/model/version.rb +43 -0
- data/lib/relaton/bib/model_autoload.rb +85 -0
- data/lib/relaton/bib/namespace_helper.rb +21 -0
- data/lib/relaton/bib/sanitizer.rb +74 -0
- data/lib/relaton/bib/util.rb +18 -0
- data/lib/relaton/bib/version.rb +5 -0
- data/lib/relaton/bib/versions.json +35 -0
- data/lib/relaton/bib.rb +41 -0
- data/relaton-bib.gemspec +12 -16
- metadata +118 -129
- data/.github/workflows/macos.yml +0 -38
- data/.github/workflows/ubuntu.yml +0 -39
- data/.github/workflows/windows.yml +0 -41
- data/grammars/basicdoc.rng +0 -986
- data/grammars/biblio.rng +0 -1237
- data/grammars/isodoc.rng +0 -1613
- data/grammars/reqt.rng +0 -165
- data/lib/relaton_bib/bib_item_locality.rb +0 -107
- data/lib/relaton_bib/biblio_note.rb +0 -44
- data/lib/relaton_bib/biblio_version.rb +0 -49
- data/lib/relaton_bib/bibliographic_date.rb +0 -90
- data/lib/relaton_bib/bibliographic_item.rb +0 -726
- data/lib/relaton_bib/bibtex_parser.rb +0 -245
- data/lib/relaton_bib/classification.rb +0 -40
- data/lib/relaton_bib/contribution_info.rb +0 -109
- data/lib/relaton_bib/contributor.rb +0 -215
- data/lib/relaton_bib/copyright_association.rb +0 -77
- data/lib/relaton_bib/deep_dup.rb +0 -30
- data/lib/relaton_bib/document_identifier.rb +0 -95
- data/lib/relaton_bib/document_relation.rb +0 -94
- data/lib/relaton_bib/document_relation_collection.rb +0 -46
- data/lib/relaton_bib/document_status.rb +0 -93
- data/lib/relaton_bib/editorial_group.rb +0 -41
- data/lib/relaton_bib/formatted_ref.rb +0 -17
- data/lib/relaton_bib/formatted_string.rb +0 -55
- data/lib/relaton_bib/hash_converter.rb +0 -497
- data/lib/relaton_bib/hit.rb +0 -46
- data/lib/relaton_bib/hit_collection.rb +0 -73
- data/lib/relaton_bib/ics.rb +0 -37
- data/lib/relaton_bib/localized_string.rb +0 -93
- data/lib/relaton_bib/medium.rb +0 -44
- data/lib/relaton_bib/organization.rb +0 -135
- data/lib/relaton_bib/person.rb +0 -206
- data/lib/relaton_bib/place.rb +0 -49
- data/lib/relaton_bib/series.rb +0 -134
- data/lib/relaton_bib/structured_identifier.rb +0 -171
- data/lib/relaton_bib/technical_committee.rb +0 -36
- data/lib/relaton_bib/typed_title_string.rb +0 -96
- data/lib/relaton_bib/typed_uri.rb +0 -47
- data/lib/relaton_bib/validity.rb +0 -52
- data/lib/relaton_bib/version.rb +0 -3
- data/lib/relaton_bib/workers_pool.rb +0 -43
- data/lib/relaton_bib/workgroup.rb +0 -46
- data/lib/relaton_bib/xml_parser.rb +0 -463
- data/lib/relaton_bib.rb +0 -44
|
@@ -1,497 +0,0 @@
|
|
|
1
|
-
module RelatonBib
|
|
2
|
-
class HashConverter
|
|
3
|
-
class << self
|
|
4
|
-
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
5
|
-
|
|
6
|
-
# @param args [Hash]
|
|
7
|
-
# @param neated [TrueClas, FalseClass] default false
|
|
8
|
-
# @return [Hash]
|
|
9
|
-
def hash_to_bib(args, nested = false)
|
|
10
|
-
return nil unless args.is_a?(Hash)
|
|
11
|
-
|
|
12
|
-
ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy
|
|
13
|
-
timestamp_hash(ret) unless nested
|
|
14
|
-
title_hash_to_bib(ret)
|
|
15
|
-
link_hash_to_bib(ret)
|
|
16
|
-
language_hash_to_bib(ret)
|
|
17
|
-
script_hash_to_bib(ret)
|
|
18
|
-
dates_hash_to_bib(ret)
|
|
19
|
-
docid_hash_to_bib(ret)
|
|
20
|
-
version_hash_to_bib(ret)
|
|
21
|
-
biblionote_hash_to_bib(ret)
|
|
22
|
-
abstract_hash_to_bib(ret)
|
|
23
|
-
formattedref_hash_to_bib(ret)
|
|
24
|
-
docstatus_hash_to_bib(ret)
|
|
25
|
-
contributors_hash_to_bib(ret)
|
|
26
|
-
copyright_hash_to_bib(ret)
|
|
27
|
-
relations_hash_to_bib(ret)
|
|
28
|
-
series_hash_to_bib(ret)
|
|
29
|
-
medium_hash_to_bib(ret)
|
|
30
|
-
place_hash_to_bib(ret)
|
|
31
|
-
extent_hash_to_bib(ret)
|
|
32
|
-
accesslocation_hash_to_bib(ret)
|
|
33
|
-
classification_hash_to_bib(ret)
|
|
34
|
-
validity_hash_to_bib(ret)
|
|
35
|
-
ret[:keyword] = array(ret[:keyword])
|
|
36
|
-
ret[:license] = array(ret[:license])
|
|
37
|
-
editorialgroup_hash_to_bib ret
|
|
38
|
-
ics_hash_to_bib ret
|
|
39
|
-
structuredidentifier_hash_to_bib ret
|
|
40
|
-
ret
|
|
41
|
-
end
|
|
42
|
-
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
|
43
|
-
|
|
44
|
-
def timestamp_hash(ret)
|
|
45
|
-
ret[:fetched] ||= Date.today.to_s
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def extent_hash_to_bib(ret)
|
|
49
|
-
return unless ret[:extent]
|
|
50
|
-
|
|
51
|
-
ret[:extent] = array(ret[:extent])
|
|
52
|
-
ret[:extent]&.each_with_index do |e, i|
|
|
53
|
-
ret[:extent][i] = BibItemLocality.new(e[:type], e[:reference_from],
|
|
54
|
-
e[:reference_to])
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def title_hash_to_bib(ret)
|
|
59
|
-
return unless ret[:title]
|
|
60
|
-
|
|
61
|
-
ret[:title] = array(ret[:title]).reduce([]) do |m, t|
|
|
62
|
-
if t.is_a?(Hash) then m << t
|
|
63
|
-
else
|
|
64
|
-
m + TypedTitleString.from_string(t)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def language_hash_to_bib(ret)
|
|
70
|
-
return unless ret[:language]
|
|
71
|
-
|
|
72
|
-
ret[:language] = array(ret[:language])
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def script_hash_to_bib(ret)
|
|
76
|
-
return unless ret[:script]
|
|
77
|
-
|
|
78
|
-
ret[:script] = array(ret[:script])
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def abstract_hash_to_bib(ret)
|
|
82
|
-
return unless ret[:abstract]
|
|
83
|
-
|
|
84
|
-
ret[:abstract] = array(ret[:abstract]).map do |a|
|
|
85
|
-
a.is_a?(String) ? FormattedString.new(content: a) : a
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def link_hash_to_bib(ret)
|
|
90
|
-
return unless ret[:link]
|
|
91
|
-
|
|
92
|
-
ret[:link] = array(ret[:link])
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def place_hash_to_bib(ret)
|
|
96
|
-
return unless ret[:place]
|
|
97
|
-
|
|
98
|
-
ret[:place] = array(ret[:place]).map do |pl|
|
|
99
|
-
pl.is_a?(String) ? Place.new(name: pl) : Place.new(pl)
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def accesslocation_hash_to_bib(ret)
|
|
104
|
-
return unless ret[:accesslocation]
|
|
105
|
-
|
|
106
|
-
ret[:accesslocation] = array(ret[:accesslocation])
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def dates_hash_to_bib(ret)
|
|
110
|
-
return unless ret[:date]
|
|
111
|
-
|
|
112
|
-
ret[:date] = array(ret[:date])
|
|
113
|
-
ret[:date].each_with_index do |d, i|
|
|
114
|
-
# value is synonym of on: it is reserved word in YAML
|
|
115
|
-
if d[:value]
|
|
116
|
-
ret[:date][i][:on] ||= d[:value]
|
|
117
|
-
ret[:date][i].delete(:value)
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def docid_hash_to_bib(ret)
|
|
123
|
-
return unless ret[:docid]
|
|
124
|
-
|
|
125
|
-
ret[:docid] = array(ret[:docid])
|
|
126
|
-
ret[:docid]&.each_with_index do |id, i|
|
|
127
|
-
type = id[:type] || id[:id].match(/^\w+/)&.to_s
|
|
128
|
-
ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: type,
|
|
129
|
-
scope: id[:scope])
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def version_hash_to_bib(ret)
|
|
134
|
-
return unless ret[:version]
|
|
135
|
-
|
|
136
|
-
ret[:version][:draft] = array(ret[:version][:draft])
|
|
137
|
-
ret[:version] && ret[:version] = BibliographicItem::Version.new(
|
|
138
|
-
ret[:version][:revision_date], ret[:version][:draft]
|
|
139
|
-
)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def biblionote_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength
|
|
143
|
-
return unless ret[:biblionote]
|
|
144
|
-
|
|
145
|
-
ret[:biblionote] = array(ret[:biblionote])
|
|
146
|
-
(ret[:biblionote])&.each_with_index do |n, i|
|
|
147
|
-
ret[:biblionote][i] = if n.is_a?(String)
|
|
148
|
-
BiblioNote.new content: n
|
|
149
|
-
else
|
|
150
|
-
BiblioNote.new(
|
|
151
|
-
content: n[:content], type: n[:type],
|
|
152
|
-
language: n[:language], script: n[:script],
|
|
153
|
-
format: n[:format]
|
|
154
|
-
)
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def formattedref_hash_to_bib(ret)
|
|
160
|
-
ret[:formattedref] &&
|
|
161
|
-
ret[:formattedref] = formattedref(ret[:formattedref])
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def docstatus_hash_to_bib(ret)
|
|
165
|
-
ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
|
|
166
|
-
stage: stage(ret[:docstatus][:stage]),
|
|
167
|
-
substage: stage(ret[:docstatus][:substage]),
|
|
168
|
-
iteration: ret[:docstatus][:iteration]
|
|
169
|
-
)
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
# @param stg [Hash]
|
|
173
|
-
# @return [RelatonBib::DocumentStatus::Stage]
|
|
174
|
-
def stage(stg)
|
|
175
|
-
return unless stg
|
|
176
|
-
|
|
177
|
-
args = stg.is_a?(String) ? { value: stg } : stg
|
|
178
|
-
DocumentStatus::Stage.new(**args)
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def contributors_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
|
182
|
-
return unless ret[:contributor]
|
|
183
|
-
|
|
184
|
-
ret[:contributor] = array(ret[:contributor])
|
|
185
|
-
ret[:contributor]&.each_with_index do |c, i|
|
|
186
|
-
roles = array(ret[:contributor][i][:role]).map do |r|
|
|
187
|
-
if r.is_a? Hash
|
|
188
|
-
{ type: r[:type], description: array(r[:description]) }
|
|
189
|
-
# elsif r.is_a? Array
|
|
190
|
-
# { type: r[0], description: r.fetch(1) }
|
|
191
|
-
else
|
|
192
|
-
{ type: r }
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
ret[:contributor][i][:role] = roles
|
|
196
|
-
ret[:contributor][i][:entity] = if c[:person]
|
|
197
|
-
person_hash_to_bib(c[:person])
|
|
198
|
-
else
|
|
199
|
-
org_hash_to_bib(c[:organization])
|
|
200
|
-
end
|
|
201
|
-
ret[:contributor][i].delete(:person)
|
|
202
|
-
ret[:contributor][i].delete(:organization)
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def org_hash_to_bib(org)
|
|
207
|
-
return nil if org.nil?
|
|
208
|
-
|
|
209
|
-
org[:identifier] = array(org[:identifier])&.map do |a|
|
|
210
|
-
OrgIdentifier.new(a[:type], a[:id])
|
|
211
|
-
end
|
|
212
|
-
org
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def person_hash_to_bib(person)
|
|
216
|
-
Person.new(
|
|
217
|
-
name: fullname_hash_to_bib(person),
|
|
218
|
-
affiliation: affiliation_hash_to_bib(person),
|
|
219
|
-
contact: contacts_hash_to_bib(person),
|
|
220
|
-
identifier: person_identifiers_hash_to_bib(person)
|
|
221
|
-
)
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
225
|
-
n = person[:name]
|
|
226
|
-
FullName.new(
|
|
227
|
-
forename: array(n[:forename])&.map { |f| localname(f, person) },
|
|
228
|
-
initial: array(n[:initial])&.map { |f| localname(f, person) },
|
|
229
|
-
addition: array(n[:addition])&.map { |f| localname(f, person) },
|
|
230
|
-
prefix: array(n[:prefix])&.map { |f| localname(f, person) },
|
|
231
|
-
surname: localname(n[:surname], person),
|
|
232
|
-
completename: localname(n[:completename], person)
|
|
233
|
-
)
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
def person_identifiers_hash_to_bib(person)
|
|
237
|
-
array(person[:identifier])&.map do |a|
|
|
238
|
-
PersonIdentifier.new(a[:type], a[:id])
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
def affiliation_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
243
|
-
return [] unless person[:affiliation]
|
|
244
|
-
|
|
245
|
-
array(person[:affiliation]).map do |a|
|
|
246
|
-
a[:description] = array(a[:description])&.map do |d|
|
|
247
|
-
cnt = if d.is_a?(Hash)
|
|
248
|
-
{ content: d[:content], language: d[:language],
|
|
249
|
-
script: d[:script], format: d[:format] }
|
|
250
|
-
else { content: d }
|
|
251
|
-
end
|
|
252
|
-
FormattedString.new cnt
|
|
253
|
-
end
|
|
254
|
-
Affiliation.new(
|
|
255
|
-
organization: Organization.new(org_hash_to_bib(a[:organization])),
|
|
256
|
-
description: a[:description]
|
|
257
|
-
)
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
def contacts_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
262
|
-
return [] unless person[:contact]
|
|
263
|
-
|
|
264
|
-
array(person[:contact]).map do |a|
|
|
265
|
-
if a[:city] || a[:country]
|
|
266
|
-
RelatonBib::Address.new(
|
|
267
|
-
street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
|
|
268
|
-
country: a[:country], state: a[:state]
|
|
269
|
-
)
|
|
270
|
-
else
|
|
271
|
-
RelatonBib::Contact.new(type: a[:type], value: a[:value])
|
|
272
|
-
end
|
|
273
|
-
end
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
# @param ret [Hash]
|
|
277
|
-
def copyright_hash_to_bib(ret)
|
|
278
|
-
return unless ret[:copyright]
|
|
279
|
-
|
|
280
|
-
ret[:copyright] = array(ret[:copyright]).map do |c|
|
|
281
|
-
c[:owner] = array(c[:owner])
|
|
282
|
-
c
|
|
283
|
-
end
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
# @param ret [Hash]
|
|
287
|
-
def relations_hash_to_bib(ret)
|
|
288
|
-
return unless ret[:relation]
|
|
289
|
-
|
|
290
|
-
ret[:relation] = array(ret[:relation])
|
|
291
|
-
ret[:relation]&.each do |r|
|
|
292
|
-
if r[:description]
|
|
293
|
-
r[:description] = FormattedString.new r[:description]
|
|
294
|
-
end
|
|
295
|
-
relation_bibitem_hash_to_bib(r)
|
|
296
|
-
relation_locality_hash_to_bib(r)
|
|
297
|
-
relation_source_locality_hash_to_bib(r)
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
# @param rel [Hash] relation
|
|
302
|
-
def relation_bibitem_hash_to_bib(rel)
|
|
303
|
-
if rel[:bibitem]
|
|
304
|
-
rel[:bibitem] = bib_item hash_to_bib(rel[:bibitem], true)
|
|
305
|
-
else
|
|
306
|
-
warn "[relaton-bib] bibitem missing: #{rel}"
|
|
307
|
-
rel[:bibitem] = nil
|
|
308
|
-
end
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
# @param item_hash [Hash]
|
|
312
|
-
# @return [RelatonBib::BibliographicItem]
|
|
313
|
-
def bib_item(item_hash)
|
|
314
|
-
BibliographicItem.new item_hash
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
# @param rel [Hash] relation
|
|
318
|
-
# @return [RelatonBib::LocalityStack]
|
|
319
|
-
def relation_locality_hash_to_bib(rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
320
|
-
rel[:locality] = array(rel[:locality])&.map do |bl|
|
|
321
|
-
ls = if bl[:locality_stack]
|
|
322
|
-
array(bl[:locality_stack]).map do |l|
|
|
323
|
-
Locality.new(l[:type], l[:reference_from], l[:reference_to])
|
|
324
|
-
end
|
|
325
|
-
else
|
|
326
|
-
l = Locality.new(bl[:type], bl[:reference_from],
|
|
327
|
-
bl[:reference_to])
|
|
328
|
-
[l]
|
|
329
|
-
end
|
|
330
|
-
LocalityStack.new ls
|
|
331
|
-
end
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
# @param rel [Hash] relation
|
|
335
|
-
def relation_source_locality_hash_to_bib(rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
336
|
-
rel[:source_locality] = array(rel[:source_locality])&.map do |sl|
|
|
337
|
-
sls = if sl[:source_locality_stack]
|
|
338
|
-
array(sl[:source_locality_stack]).map do |l|
|
|
339
|
-
SourceLocality.new(l[:type], l[:reference_from],
|
|
340
|
-
l[:reference_to])
|
|
341
|
-
end
|
|
342
|
-
else
|
|
343
|
-
l = SourceLocality.new(sl[:type], sl[:reference_from],
|
|
344
|
-
sl[:reference_to])
|
|
345
|
-
[l]
|
|
346
|
-
end
|
|
347
|
-
SourceLocalityStack.new sls
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
# @param ret [Hash]
|
|
352
|
-
def series_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
353
|
-
ret[:series] = array(ret[:series])&.map do |s|
|
|
354
|
-
s[:formattedref] && s[:formattedref] = formattedref(s[:formattedref])
|
|
355
|
-
if s[:title]
|
|
356
|
-
s[:title] = { content: s[:title] } unless s[:title].is_a?(Hash)
|
|
357
|
-
s[:title] = typed_title_strig(s[:title])
|
|
358
|
-
end
|
|
359
|
-
s[:abbreviation] &&
|
|
360
|
-
s[:abbreviation] = localizedstring(s[:abbreviation])
|
|
361
|
-
Series.new(s)
|
|
362
|
-
end
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
# @param title [Hash]
|
|
366
|
-
# @return [RelatonBib::TypedTitleString]
|
|
367
|
-
def typed_title_strig(title)
|
|
368
|
-
TypedTitleString.new title
|
|
369
|
-
end
|
|
370
|
-
|
|
371
|
-
# @param ret [Hash]
|
|
372
|
-
def medium_hash_to_bib(ret)
|
|
373
|
-
ret[:medium] = Medium.new(ret[:medium]) if ret[:medium]
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
# @param ret [Hash]
|
|
377
|
-
def classification_hash_to_bib(ret)
|
|
378
|
-
if ret[:classification]
|
|
379
|
-
ret[:classification] = array(ret[:classification]).map do |cls|
|
|
380
|
-
Classification.new cls
|
|
381
|
-
end
|
|
382
|
-
end
|
|
383
|
-
end
|
|
384
|
-
|
|
385
|
-
# @param ret [Hash]
|
|
386
|
-
def validity_hash_to_bib(ret)
|
|
387
|
-
return unless ret[:validity]
|
|
388
|
-
|
|
389
|
-
b = parse_validity_time(ret[:validity], :begins)
|
|
390
|
-
e = parse_validity_time(ret[:validity], :ends)
|
|
391
|
-
r = parse_validity_time(ret[:validity], :revision)
|
|
392
|
-
ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
|
|
393
|
-
end
|
|
394
|
-
|
|
395
|
-
def parse_validity_time(val, period)
|
|
396
|
-
t = val[period]&.to_s
|
|
397
|
-
return unless t
|
|
398
|
-
|
|
399
|
-
p = period == :ends ? -1 : 1
|
|
400
|
-
case t
|
|
401
|
-
when /^\d{4}$/
|
|
402
|
-
Date.new(t.to_i, p, p).to_time
|
|
403
|
-
when /^(?<year>\d{4})-(?<month>\d{1,2})$/
|
|
404
|
-
Date.new($~[:year].to_i, $~[:month].to_i, p).to_time
|
|
405
|
-
else Time.parse t
|
|
406
|
-
end
|
|
407
|
-
end
|
|
408
|
-
|
|
409
|
-
# @param ret [Hash]
|
|
410
|
-
def editorialgroup_hash_to_bib(ret)
|
|
411
|
-
return unless ret[:editorialgroup]
|
|
412
|
-
|
|
413
|
-
technical_committee = array(ret[:editorialgroup]).map do |wg|
|
|
414
|
-
TechnicalCommittee.new WorkGroup.new(wg)
|
|
415
|
-
end
|
|
416
|
-
ret[:editorialgroup] = EditorialGroup.new technical_committee
|
|
417
|
-
end
|
|
418
|
-
|
|
419
|
-
# @param ret [Hash]
|
|
420
|
-
def ics_hash_to_bib(ret)
|
|
421
|
-
return unless ret[:ics]
|
|
422
|
-
|
|
423
|
-
ret[:ics] = array(ret[:ics]).map { |ics| ICS.new ics }
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
# @param ret [Hash]
|
|
427
|
-
def structuredidentifier_hash_to_bib(ret)
|
|
428
|
-
return unless ret[:structuredidentifier]
|
|
429
|
-
|
|
430
|
-
sids = array(ret[:structuredidentifier]).map do |si|
|
|
431
|
-
si[:agency] = array si[:agency]
|
|
432
|
-
StructuredIdentifier.new si
|
|
433
|
-
end
|
|
434
|
-
ret[:structuredidentifier] = StructuredIdentifierCollection.new sids
|
|
435
|
-
end
|
|
436
|
-
|
|
437
|
-
# @param ogj [Hash, Array, String]
|
|
438
|
-
# @return [Hash, Array, String]
|
|
439
|
-
def symbolize(obj)
|
|
440
|
-
if obj.is_a? Hash
|
|
441
|
-
obj.reduce({}) do |memo, (k, v)|
|
|
442
|
-
memo[k.to_sym] = symbolize(v)
|
|
443
|
-
memo
|
|
444
|
-
end
|
|
445
|
-
elsif obj.is_a? Array
|
|
446
|
-
obj.reduce([]) { |memo, v| memo << symbolize(v) }
|
|
447
|
-
else
|
|
448
|
-
obj
|
|
449
|
-
end
|
|
450
|
-
end
|
|
451
|
-
|
|
452
|
-
# @param arr [NilClass, Array, #is_a?]
|
|
453
|
-
# @return [Array]
|
|
454
|
-
def array(arr)
|
|
455
|
-
return [] unless arr
|
|
456
|
-
return [arr] unless arr.is_a?(Array)
|
|
457
|
-
|
|
458
|
-
arr
|
|
459
|
-
end
|
|
460
|
-
|
|
461
|
-
# @param name [Hash, String, NilClass]
|
|
462
|
-
# @param person [Hash]
|
|
463
|
-
# @return [RelatonBib::LocalizedString]
|
|
464
|
-
def localname(name, person) # rubocop:disable Metrics/CyclomaticComplexity
|
|
465
|
-
return nil if name.nil?
|
|
466
|
-
|
|
467
|
-
lang = name[:language] if name.is_a?(Hash)
|
|
468
|
-
lang ||= person[:name][:language]
|
|
469
|
-
script = name[:script] if name.is_a?(Hash)
|
|
470
|
-
script ||= person[:name][:script]
|
|
471
|
-
n = name.is_a?(Hash) ? name[:content] : name
|
|
472
|
-
RelatonBib::LocalizedString.new(n, lang, script)
|
|
473
|
-
end
|
|
474
|
-
|
|
475
|
-
# @param lst [Hash, Array<RelatonBib::LocalizedString>]
|
|
476
|
-
# @return [RelatonBib::LocalizedString]
|
|
477
|
-
def localizedstring(lst)
|
|
478
|
-
if lst.is_a?(Hash)
|
|
479
|
-
RelatonBib::LocalizedString.new(lst[:content], lst[:language],
|
|
480
|
-
lst[:script])
|
|
481
|
-
else
|
|
482
|
-
RelatonBib::LocalizedString.new(lst)
|
|
483
|
-
end
|
|
484
|
-
end
|
|
485
|
-
|
|
486
|
-
# @param frf [Hash, String]
|
|
487
|
-
# @return [RelatonBib::FormattedRef]
|
|
488
|
-
def formattedref(frf)
|
|
489
|
-
if frf.is_a?(Hash)
|
|
490
|
-
RelatonBib::FormattedRef.new(frf)
|
|
491
|
-
else
|
|
492
|
-
RelatonBib::FormattedRef.new(content: frf)
|
|
493
|
-
end
|
|
494
|
-
end
|
|
495
|
-
end
|
|
496
|
-
end
|
|
497
|
-
end
|
data/lib/relaton_bib/hit.rb
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
module RelatonBib
|
|
2
|
-
class Hit
|
|
3
|
-
# @return [RelatonBib::HitCollection]
|
|
4
|
-
attr_reader :hit_collection
|
|
5
|
-
|
|
6
|
-
# @return [Array<Hash>]
|
|
7
|
-
attr_reader :hit
|
|
8
|
-
|
|
9
|
-
# @param hit [Hash]
|
|
10
|
-
# @param hit_collection [RelatonIso::HitCollection, RelatonNist:HitCollection]
|
|
11
|
-
def initialize(hit, hit_collection = nil)
|
|
12
|
-
@hit = hit
|
|
13
|
-
@hit_collection = hit_collection
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# @return [String]
|
|
17
|
-
def to_s
|
|
18
|
-
inspect
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# @return [String]
|
|
22
|
-
def inspect
|
|
23
|
-
"<#{self.class}:#{format('%#.14x', object_id << 1)} "\
|
|
24
|
-
"@text=\"#{@hit_collection&.text}\" "\
|
|
25
|
-
"@fetched=\"#{!@fetch.nil?}\" "\
|
|
26
|
-
"@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
|
|
27
|
-
"@title=\"#{@hit[:code]}\">"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def fetch
|
|
31
|
-
raise "Not implemented"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# @param builder [Nokogiri::XML::Builder]
|
|
35
|
-
def to_xml(builder = nil, **opts)
|
|
36
|
-
if builder
|
|
37
|
-
fetch.to_xml builder, **opts
|
|
38
|
-
else
|
|
39
|
-
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
|
40
|
-
fetch.to_xml xml, **opts
|
|
41
|
-
end
|
|
42
|
-
builder.doc.root.to_xml
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require "forwardable"
|
|
2
|
-
|
|
3
|
-
module RelatonBib
|
|
4
|
-
class HitCollection
|
|
5
|
-
extend Forwardable
|
|
6
|
-
|
|
7
|
-
def_delegators :@array, :<<, :[], :first, :empty?, :any?, :size, :each, :each_slice
|
|
8
|
-
|
|
9
|
-
# @return [TrueClass, FalseClass]
|
|
10
|
-
attr_reader :fetched
|
|
11
|
-
|
|
12
|
-
# @return [String]
|
|
13
|
-
attr_reader :text
|
|
14
|
-
|
|
15
|
-
# @return [String]
|
|
16
|
-
attr_reader :year
|
|
17
|
-
|
|
18
|
-
# @param text [String] reference to search
|
|
19
|
-
def initialize(text, year = nil)
|
|
20
|
-
@array = []
|
|
21
|
-
@text = text
|
|
22
|
-
@year = year
|
|
23
|
-
@fetched = false
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# @return [RelatonIso::HitCollection]
|
|
27
|
-
def fetch
|
|
28
|
-
workers = WorkersPool.new 4
|
|
29
|
-
workers.worker(&:fetch)
|
|
30
|
-
each do |hit|
|
|
31
|
-
workers << hit
|
|
32
|
-
end
|
|
33
|
-
workers.end
|
|
34
|
-
workers.result
|
|
35
|
-
@fetched = true
|
|
36
|
-
self
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def to_xml(**opts)
|
|
40
|
-
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
|
41
|
-
xml.documents do
|
|
42
|
-
@array.each do |hit|
|
|
43
|
-
hit.fetch
|
|
44
|
-
hit.to_xml xml, **opts
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
builder.to_xml
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def select(&block)
|
|
52
|
-
me = self.deep_dup
|
|
53
|
-
array_dup = self.instance_variable_get(:@array).deep_dup
|
|
54
|
-
me.instance_variable_set(:@array, array_dup)
|
|
55
|
-
array_dup.select!(&block)
|
|
56
|
-
me
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def reduce!(sum, &block)
|
|
60
|
-
@array = @array.reduce sum, &block
|
|
61
|
-
self
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def to_s
|
|
65
|
-
inspect
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# @return [String]
|
|
69
|
-
def inspect
|
|
70
|
-
"<#{self.class}:#{format('%#.14x', object_id << 1)} @ref=#{@text} @fetched=#{@fetched}>"
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
data/lib/relaton_bib/ics.rb
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
module RelatonBib
|
|
2
|
-
class ICS
|
|
3
|
-
# @return [String]
|
|
4
|
-
attr_reader :code, :text
|
|
5
|
-
|
|
6
|
-
# @param code [String]
|
|
7
|
-
# @param text [String]
|
|
8
|
-
def initialize(code:, text:)
|
|
9
|
-
@code = code
|
|
10
|
-
@text = text
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# @param builder [Nokogiri::XML::Builder]
|
|
14
|
-
def to_xml(builder)
|
|
15
|
-
builder.ics do |b|
|
|
16
|
-
b.code code
|
|
17
|
-
b.text_ text
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# @return [Hash]
|
|
22
|
-
def to_hash
|
|
23
|
-
{ "code" => code, "text" => text }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# @param prefix [String]
|
|
27
|
-
# @param count [Integer] number of ics
|
|
28
|
-
# @return [String]
|
|
29
|
-
def to_asciibib(prefix = "", count = 1)
|
|
30
|
-
pref = prefix.empty? ? "ics" : prefix + ".ics"
|
|
31
|
-
out = count > 1 ? "#{pref}::\n" : ""
|
|
32
|
-
out += "#{pref}.code:: #{code}\n"
|
|
33
|
-
out += "#{pref}.text:: #{text}\n"
|
|
34
|
-
out
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|