relaton-bib 1.16.5 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/relaton_bib/bibliographic_item.rb +9 -6
- data/lib/relaton_bib/bibxml_parser.rb +6 -5
- data/lib/relaton_bib/document_type.rb +52 -0
- data/lib/relaton_bib/hash_converter.rb +415 -402
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +8 -1
- data/lib/relaton_bib.rb +1 -0
- data/relaton-bib.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f5805d9364d7a5f74ce37acdeb99ea547d928d276541ec7d01870621330f2f1
|
4
|
+
data.tar.gz: 2aff2d7bd6fca3bb87a34509a7b61995f3dcd0eb4bdb68b60e940887eedc4c78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c061fc2df92d1c1418aa9a807e496ec736eec5eddfe5734ce0bdcc3c21995c3abd22fbc9162383f2370a7546f7836b325732f92bbc65ae9484124740cf5f406
|
7
|
+
data.tar.gz: 21c72729a63efff9cf5a312018206b22a8da1a77e4708e27610b2c92c8a4571c0a1cb5b0af973eb5285b4e0fb111353e73499ef00bee45d40cbce7cdc5d7d0f2
|
@@ -46,9 +46,12 @@ module RelatonBib
|
|
46
46
|
attr_accessor :all_parts
|
47
47
|
|
48
48
|
# @return [String, nil]
|
49
|
-
attr_reader :id, :type, :docnumber, :
|
49
|
+
attr_reader :id, :type, :docnumber, :subdoctype
|
50
50
|
|
51
|
-
# @return [RelatonBib::
|
51
|
+
# @return [RelatonBib::DocumentType] document type
|
52
|
+
attr_reader :doctype
|
53
|
+
|
54
|
+
# @return [RelatonBib::Edition, nil] edition
|
52
55
|
attr_reader :edition
|
53
56
|
|
54
57
|
# @!attribute [r] title
|
@@ -157,7 +160,7 @@ module RelatonBib
|
|
157
160
|
# @param validity [RelatonBib:Validity, nil]
|
158
161
|
# @param fetched [Date, nil] default nil
|
159
162
|
# @param keyword [Array<String>]
|
160
|
-
# @param doctype [
|
163
|
+
# @param doctype [RelatonBib::DocumentType]
|
161
164
|
# @param subdoctype [String]
|
162
165
|
# @param editorialgroup [RelatonBib::EditorialGroup, nil]
|
163
166
|
# @param ics [Array<RelatonBib::ICS>]
|
@@ -421,7 +424,7 @@ module RelatonBib
|
|
421
424
|
hash["fetched"] = fetched.to_s if fetched
|
422
425
|
hash["keyword"] = single_element_array(keyword) if keyword&.any?
|
423
426
|
hash["license"] = single_element_array(license) if license&.any?
|
424
|
-
hash["doctype"] = doctype if doctype
|
427
|
+
hash["doctype"] = doctype.to_hash if doctype
|
425
428
|
hash["subdoctype"] = subdoctype if subdoctype
|
426
429
|
if editorialgroup&.presence?
|
427
430
|
hash["editorialgroup"] = editorialgroup.to_hash
|
@@ -576,7 +579,7 @@ module RelatonBib
|
|
576
579
|
end
|
577
580
|
out += relation.to_asciibib prefix if relation
|
578
581
|
series.each { |s| out += s.to_asciibib prefix, series.size }
|
579
|
-
out +=
|
582
|
+
out += doctype.to_asciibib prefix if doctype
|
580
583
|
out += "#{pref}subdoctype:: #{subdoctype}\n" if subdoctype
|
581
584
|
out += "#{pref}formattedref:: #{formattedref}\n" if formattedref
|
582
585
|
keyword.each { |kw| out += kw.to_asciibib "#{pref}keyword", keyword.size }
|
@@ -639,7 +642,7 @@ module RelatonBib
|
|
639
642
|
elsif opts[:bibdata] && (doctype || editorialgroup || ics&.any? ||
|
640
643
|
structuredidentifier&.presence?)
|
641
644
|
ext = builder.ext do |b|
|
642
|
-
|
645
|
+
doctype.to_xml b if doctype
|
643
646
|
b.subdoctype subdoctype if subdoctype
|
644
647
|
editorialgroup&.to_xml b
|
645
648
|
ics.each { |i| i.to_xml b }
|
@@ -409,11 +409,12 @@ module RelatonBib
|
|
409
409
|
# @param anchor [String]
|
410
410
|
# @return [String]
|
411
411
|
def doctype(anchor)
|
412
|
-
case anchor
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
412
|
+
type = case anchor
|
413
|
+
when /I-D/ then "internet-draft"
|
414
|
+
when /IEEE/ then "ieee"
|
415
|
+
else "rfc"
|
416
|
+
end
|
417
|
+
DocumentType.new type: type
|
417
418
|
end
|
418
419
|
|
419
420
|
extend BibXMLParser
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module RelatonBib
|
2
|
+
class DocumentType
|
3
|
+
attr_reader :type, :abbreviation
|
4
|
+
|
5
|
+
#
|
6
|
+
# Initialize a DocumentType.
|
7
|
+
#
|
8
|
+
# @param [String] type document type
|
9
|
+
# @param [String, nil] abbreviation type abbreviation
|
10
|
+
#
|
11
|
+
def initialize(type:, abbreviation: nil)
|
12
|
+
@type = type
|
13
|
+
@abbreviation = abbreviation
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Build XML representation of the document type.
|
18
|
+
#
|
19
|
+
# @param [Nokogiri::XML::Builder] builder XML builder
|
20
|
+
#
|
21
|
+
def to_xml(builder)
|
22
|
+
xml = builder.doctype @type
|
23
|
+
xml[:abbreviation] = @abbreviation if @abbreviation
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Hash representation of the document type.
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
#
|
31
|
+
def to_hash
|
32
|
+
hash = { "type" => @type }
|
33
|
+
hash["abbreviation"] = @abbreviation if @abbreviation
|
34
|
+
hash
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Asciibib representation of the document type.
|
39
|
+
#
|
40
|
+
# @param [String] prefix prefix
|
41
|
+
#
|
42
|
+
# @return [String] AsciiBib representation
|
43
|
+
#
|
44
|
+
def to_asciibib(prefix = "")
|
45
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
46
|
+
pref += "doctype."
|
47
|
+
out = "#{pref}type:: #{@type}\n"
|
48
|
+
out += "#{pref}abbreviation:: #{@abbreviation}\n" if @abbreviation
|
49
|
+
out
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,521 +1,534 @@
|
|
1
1
|
module RelatonBib
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
2
|
+
module HashConverter
|
3
|
+
extend self
|
4
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
5
|
+
|
6
|
+
# @param args [Hash]
|
7
|
+
# @return [Hash]
|
8
|
+
def hash_to_bib(args)
|
9
|
+
return nil unless args.is_a?(Hash)
|
10
|
+
|
11
|
+
ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy
|
12
|
+
title_hash_to_bib(ret)
|
13
|
+
link_hash_to_bib(ret)
|
14
|
+
language_hash_to_bib(ret)
|
15
|
+
script_hash_to_bib(ret)
|
16
|
+
dates_hash_to_bib(ret)
|
17
|
+
docid_hash_to_bib(ret)
|
18
|
+
version_hash_to_bib(ret)
|
19
|
+
biblionote_hash_to_bib(ret)
|
20
|
+
abstract_hash_to_bib(ret)
|
21
|
+
formattedref_hash_to_bib(ret)
|
22
|
+
docstatus_hash_to_bib(ret)
|
23
|
+
contributors_hash_to_bib(ret)
|
24
|
+
copyright_hash_to_bib(ret)
|
25
|
+
relations_hash_to_bib(ret)
|
26
|
+
series_hash_to_bib(ret)
|
27
|
+
medium_hash_to_bib(ret)
|
28
|
+
place_hash_to_bib(ret)
|
29
|
+
extent_hash_to_bib(ret)
|
30
|
+
size_hash_to_bib(ret)
|
31
|
+
accesslocation_hash_to_bib(ret)
|
32
|
+
classification_hash_to_bib(ret)
|
33
|
+
validity_hash_to_bib(ret)
|
34
|
+
keyword_hash_to_bib(ret)
|
35
|
+
# ret[:keyword] = RelatonBib.array(ret[:keyword])
|
36
|
+
ret[:license] = RelatonBib.array(ret[:license])
|
37
|
+
editorialgroup_hash_to_bib ret
|
38
|
+
ics_hash_to_bib ret
|
39
|
+
structuredidentifier_hash_to_bib ret
|
40
|
+
doctype_hash_to_bib ret
|
41
|
+
ret
|
42
|
+
end
|
43
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
44
|
+
|
45
|
+
def keyword_hash_to_bib(ret)
|
46
|
+
ret[:keyword] = RelatonBib.array(ret[:keyword]).map do |keyword|
|
47
|
+
localizedstring keyword
|
48
48
|
end
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
def extent_hash_to_bib(ret)
|
52
|
+
return unless ret[:extent]
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
54
|
+
ret[:extent] = RelatonBib.array(ret[:extent]).map do |e|
|
55
|
+
locality e
|
56
|
+
# ret[:extent][i] = Locality.new(e[:type], e[:reference_from],
|
57
|
+
# e[:reference_to])
|
58
58
|
end
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
61
|
+
def locality(loc)
|
62
|
+
if loc[:locality_stack]
|
63
|
+
LocalityStack.new(loc[:locality_stack].map { |l| locality(l) })
|
64
|
+
else
|
65
|
+
l = loc[:locality]
|
66
|
+
Locality.new(l[:type], l[:reference_from], l[:reference_to])
|
67
67
|
end
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
def size_hash_to_bib(ret)
|
71
|
+
return unless ret[:size]
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
ret[:size] = BibliographicSize.new(size)
|
73
|
+
ret[:size] = RelatonBib.array(ret[:size])
|
74
|
+
size = ret[:size]&.map do |val|
|
75
|
+
BibliographicSize::Value.new(**val)
|
77
76
|
end
|
77
|
+
ret[:size] = BibliographicSize.new(size)
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
def title_hash_to_bib(ret)
|
81
|
+
return unless ret[:title]
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
83
|
+
ret[:title] = RelatonBib.array(ret[:title])
|
84
|
+
.reduce(TypedTitleStringCollection.new) do |m, t|
|
85
|
+
if t.is_a?(Hash) then m << TypedTitleString.new(**t)
|
86
|
+
else
|
87
|
+
m + TypedTitleString.from_string(t)
|
88
88
|
end
|
89
89
|
end
|
90
|
+
end
|
90
91
|
|
91
|
-
|
92
|
-
|
92
|
+
def language_hash_to_bib(ret)
|
93
|
+
return unless ret[:language]
|
93
94
|
|
94
|
-
|
95
|
-
|
95
|
+
ret[:language] = RelatonBib.array(ret[:language])
|
96
|
+
end
|
96
97
|
|
97
|
-
|
98
|
-
|
98
|
+
def script_hash_to_bib(ret)
|
99
|
+
return unless ret[:script]
|
99
100
|
|
100
|
-
|
101
|
-
|
101
|
+
ret[:script] = RelatonBib.array(ret[:script])
|
102
|
+
end
|
102
103
|
|
103
|
-
|
104
|
-
|
104
|
+
def abstract_hash_to_bib(ret)
|
105
|
+
return unless ret[:abstract]
|
105
106
|
|
106
|
-
|
107
|
-
|
108
|
-
end
|
107
|
+
ret[:abstract] = RelatonBib.array(ret[:abstract]).map do |a|
|
108
|
+
a.is_a?(String) ? FormattedString.new(content: a) : a
|
109
109
|
end
|
110
|
+
end
|
110
111
|
|
111
|
-
|
112
|
-
|
112
|
+
def link_hash_to_bib(ret)
|
113
|
+
return unless ret[:link]
|
113
114
|
|
114
|
-
|
115
|
-
|
115
|
+
ret[:link] = RelatonBib.array(ret[:link])
|
116
|
+
end
|
116
117
|
|
117
|
-
|
118
|
-
|
118
|
+
def place_hash_to_bib(ret)
|
119
|
+
return unless ret[:place]
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
end
|
121
|
+
ret[:place] = RelatonBib.array(ret[:place]).map do |pl|
|
122
|
+
pl.is_a?(String) ? Place.new(name: pl) : Place.new(**pl)
|
123
123
|
end
|
124
|
+
end
|
124
125
|
|
125
|
-
|
126
|
-
|
126
|
+
def accesslocation_hash_to_bib(ret)
|
127
|
+
return unless ret[:accesslocation]
|
127
128
|
|
128
|
-
|
129
|
-
|
129
|
+
ret[:accesslocation] = RelatonBib.array(ret[:accesslocation])
|
130
|
+
end
|
130
131
|
|
131
|
-
|
132
|
-
|
132
|
+
def dates_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
|
133
|
+
return unless ret[:date]
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end
|
135
|
+
ret[:date] = RelatonBib.array(ret[:date])
|
136
|
+
ret[:date].each_with_index do |d, i|
|
137
|
+
# value is synonym of on: it is reserved word in YAML
|
138
|
+
if d[:value]
|
139
|
+
ret[:date][i][:on] ||= d[:value]
|
140
|
+
ret[:date][i].delete(:value)
|
141
141
|
end
|
142
142
|
end
|
143
|
+
end
|
143
144
|
|
144
|
-
|
145
|
-
|
145
|
+
def docid_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
|
146
|
+
return unless ret[:docid]
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
end
|
148
|
+
ret[:docid] = RelatonBib.array(ret[:docid]).map do |id|
|
149
|
+
id[:type] ||= id[:id].match(/^\w+(?=\s)/)&.to_s
|
150
|
+
create_docid(**id)
|
151
151
|
end
|
152
|
+
end
|
152
153
|
|
153
|
-
|
154
|
-
|
155
|
-
|
154
|
+
def create_docid(**args)
|
155
|
+
DocumentIdentifier.new(**args)
|
156
|
+
end
|
156
157
|
|
157
|
-
|
158
|
-
|
158
|
+
def version_hash_to_bib(ret)
|
159
|
+
return unless ret[:version]
|
159
160
|
|
160
|
-
|
161
|
-
|
162
|
-
end
|
161
|
+
ret[:version] = RelatonBib.array(ret[:version]).map do |v|
|
162
|
+
BibliographicItem::Version.new(v[:revision_date], v[:draft])
|
163
163
|
end
|
164
|
+
end
|
164
165
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
ret[:biblionote] = RelatonBib.array(ret[:biblionote])
|
169
|
-
.reduce(BiblioNoteCollection.new([])) do |mem, n|
|
170
|
-
mem << if n.is_a?(String) then BiblioNote.new content: n
|
171
|
-
else BiblioNote.new(**n)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
166
|
+
def biblionote_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
167
|
+
return unless ret[:biblionote]
|
175
168
|
|
176
|
-
|
177
|
-
|
178
|
-
|
169
|
+
ret[:biblionote] = RelatonBib.array(ret[:biblionote])
|
170
|
+
.reduce(BiblioNoteCollection.new([])) do |mem, n|
|
171
|
+
mem << if n.is_a?(String) then BiblioNote.new content: n
|
172
|
+
else BiblioNote.new(**n)
|
173
|
+
end
|
179
174
|
end
|
175
|
+
end
|
180
176
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
iteration: ret[:docstatus][:iteration],
|
186
|
-
)
|
187
|
-
end
|
177
|
+
def formattedref_hash_to_bib(ret)
|
178
|
+
ret[:formattedref] &&
|
179
|
+
ret[:formattedref] = formattedref(ret[:formattedref])
|
180
|
+
end
|
188
181
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
182
|
+
def docstatus_hash_to_bib(ret)
|
183
|
+
ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
|
184
|
+
stage: stage(ret[:docstatus][:stage]),
|
185
|
+
substage: stage(ret[:docstatus][:substage]),
|
186
|
+
iteration: ret[:docstatus][:iteration],
|
187
|
+
)
|
188
|
+
end
|
193
189
|
|
194
|
-
|
195
|
-
|
196
|
-
|
190
|
+
# @param stg [Hash]
|
191
|
+
# @return [RelatonBib::DocumentStatus::Stage]
|
192
|
+
def stage(stg)
|
193
|
+
return unless stg
|
197
194
|
|
198
|
-
|
199
|
-
|
195
|
+
args = stg.is_a?(String) ? { value: stg } : stg
|
196
|
+
DocumentStatus::Stage.new(**args)
|
197
|
+
end
|
200
198
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
199
|
+
def contributors_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
|
200
|
+
return unless ret[:contributor]
|
201
|
+
|
202
|
+
ret[:contributor] = RelatonBib.array(ret[:contributor])
|
203
|
+
ret[:contributor]&.each_with_index do |c, i|
|
204
|
+
roles = RelatonBib.array(ret[:contributor][i][:role]).map do |r|
|
205
|
+
if r.is_a? Hash
|
206
|
+
desc = RelatonBib.array(r[:description]).map { |d| d.is_a?(String) ? d : d[:content] }
|
207
|
+
{ type: r[:type], description: desc }
|
208
|
+
# elsif r.is_a? Array
|
209
|
+
# { type: r[0], description: r.fetch(1) }
|
210
|
+
else
|
211
|
+
{ type: r }
|
212
212
|
end
|
213
|
-
ret[:contributor][i][:role] = roles
|
214
|
-
ret[:contributor][i][:entity] = if c[:person]
|
215
|
-
person_hash_to_bib(c[:person])
|
216
|
-
else
|
217
|
-
org_hash_to_bib(c[:organization])
|
218
|
-
end
|
219
|
-
ret[:contributor][i].delete(:person)
|
220
|
-
ret[:contributor][i].delete(:organization)
|
221
213
|
end
|
214
|
+
ret[:contributor][i][:role] = roles
|
215
|
+
ret[:contributor][i][:entity] = if c[:person]
|
216
|
+
person_hash_to_bib(c[:person])
|
217
|
+
else
|
218
|
+
org_hash_to_bib(c[:organization])
|
219
|
+
end
|
220
|
+
ret[:contributor][i].delete(:person)
|
221
|
+
ret[:contributor][i].delete(:organization)
|
222
222
|
end
|
223
|
+
end
|
223
224
|
|
224
|
-
|
225
|
-
|
225
|
+
def org_hash_to_bib(org) # rubocop:disable Metrics/AbcSize
|
226
|
+
return nil if org.nil?
|
226
227
|
|
227
|
-
|
228
|
-
|
229
|
-
end
|
230
|
-
org[:subdivision] = RelatonBib.array(org[:subdivision]).map do |sd|
|
231
|
-
LocalizedString.new sd
|
232
|
-
end
|
233
|
-
org[:contact] = contacts_hash_to_bib(org)
|
234
|
-
org
|
228
|
+
org[:identifier] = RelatonBib.array(org[:identifier])&.map do |a|
|
229
|
+
OrgIdentifier.new(a[:type], a[:id])
|
235
230
|
end
|
236
|
-
|
237
|
-
|
238
|
-
Person.new(
|
239
|
-
name: fullname_hash_to_bib(person),
|
240
|
-
affiliation: affiliation_hash_to_bib(person),
|
241
|
-
contact: contacts_hash_to_bib(person),
|
242
|
-
identifier: person_identifiers_hash_to_bib(person),
|
243
|
-
)
|
231
|
+
org[:subdivision] = RelatonBib.array(org[:subdivision]).map do |sd|
|
232
|
+
LocalizedString.new sd
|
244
233
|
end
|
234
|
+
org[:contact] = contacts_hash_to_bib(org)
|
235
|
+
org
|
236
|
+
end
|
245
237
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
completename: localizedstring(n[:completename])
|
255
|
-
)
|
256
|
-
end
|
238
|
+
def person_hash_to_bib(person)
|
239
|
+
Person.new(
|
240
|
+
name: fullname_hash_to_bib(person),
|
241
|
+
affiliation: affiliation_hash_to_bib(person),
|
242
|
+
contact: contacts_hash_to_bib(person),
|
243
|
+
identifier: person_identifiers_hash_to_bib(person),
|
244
|
+
)
|
245
|
+
end
|
257
246
|
|
258
|
-
|
259
|
-
|
247
|
+
def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize
|
248
|
+
n = person[:name]
|
249
|
+
fname, inits = given_hash_to_bib n[:given] || n # `n` is for backward compatibility
|
250
|
+
FullName.new(
|
251
|
+
forename: fname, initials: inits,
|
252
|
+
addition: RelatonBib.array(n[:addition])&.map { |f| localizedstring(f) },
|
253
|
+
prefix: RelatonBib.array(n[:prefix])&.map { |f| localizedstring(f) },
|
254
|
+
surname: localizedstring(n[:surname]),
|
255
|
+
completename: localizedstring(n[:completename])
|
256
|
+
)
|
257
|
+
end
|
260
258
|
|
261
|
-
|
262
|
-
|
263
|
-
[fname, inits]
|
264
|
-
end
|
259
|
+
def given_hash_to_bib(given)
|
260
|
+
return [[], nil] unless given
|
265
261
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
262
|
+
fname = RelatonBib.array(given[:forename])&.map { |f| forename_hash_to_bib(f) }
|
263
|
+
inits = localizedstring(given[:formatted_initials])
|
264
|
+
[fname, inits]
|
265
|
+
end
|
266
|
+
|
267
|
+
def forename_hash_to_bib(fname)
|
268
|
+
case fname
|
269
|
+
when Hash then Forename.new(**fname)
|
270
|
+
when String then Forename.new(content: fname)
|
271
271
|
end
|
272
|
+
end
|
272
273
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
end
|
274
|
+
def person_identifiers_hash_to_bib(person)
|
275
|
+
RelatonBib.array(person[:identifier])&.map do |a|
|
276
|
+
PersonIdentifier.new(a[:type], a[:id])
|
277
277
|
end
|
278
|
+
end
|
278
279
|
|
279
|
-
|
280
|
-
|
280
|
+
def affiliation_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
281
|
+
return [] unless person[:affiliation]
|
281
282
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
end
|
291
|
-
name = LocalizedString.new(a[:name][:content], a[:name][:language], a[:name][:script]) if a[:name]
|
292
|
-
Affiliation.new(
|
293
|
-
organization: Organization.new(**org_hash_to_bib(a[:organization])),
|
294
|
-
description: a[:description], name: name
|
295
|
-
)
|
283
|
+
RelatonBib.array(person[:affiliation]).map do |a|
|
284
|
+
a[:description] = RelatonBib.array(a[:description]).map do |d|
|
285
|
+
cnt = if d.is_a?(Hash)
|
286
|
+
{ content: d[:content], language: d[:language],
|
287
|
+
script: d[:script], format: d[:format] }
|
288
|
+
else { content: d }
|
289
|
+
end
|
290
|
+
FormattedString.new(**cnt)
|
296
291
|
end
|
292
|
+
name = LocalizedString.new(a[:name][:content], a[:name][:language], a[:name][:script]) if a[:name]
|
293
|
+
Affiliation.new(
|
294
|
+
organization: Organization.new(**org_hash_to_bib(a[:organization])),
|
295
|
+
description: a[:description], name: name
|
296
|
+
)
|
297
297
|
end
|
298
|
+
end
|
298
299
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
end
|
300
|
+
def contacts_hash_to_bib(entity) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity
|
301
|
+
return [] unless entity[:contact]
|
302
|
+
|
303
|
+
RelatonBib.array(entity[:contact]).map do |a|
|
304
|
+
if a[:city] || a[:country] # it's for old version compatibility, should be removed in the future
|
305
|
+
RelatonBib::Address.new(
|
306
|
+
street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
|
307
|
+
country: a[:country], state: a[:state]
|
308
|
+
)
|
309
|
+
elsif a[:address]
|
310
|
+
a[:address][:street] = RelatonBib.array(a[:address][:street])
|
311
|
+
RelatonBib::Address.new(**a[:address])
|
312
|
+
elsif a[:type] # it's for old version compatibility, should be removed in the future
|
313
|
+
RelatonBib::Contact.new(type: a[:type], value: a[:value])
|
314
|
+
else
|
315
|
+
type, value = a.flatten
|
316
|
+
RelatonBib::Contact.new(type: type.to_s, value: value)
|
317
317
|
end
|
318
318
|
end
|
319
|
+
end
|
319
320
|
|
320
|
-
|
321
|
-
|
322
|
-
|
321
|
+
# @param ret [Hash]
|
322
|
+
def copyright_hash_to_bib(ret)
|
323
|
+
return unless ret[:copyright]
|
323
324
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
end
|
328
|
-
c
|
325
|
+
ret[:copyright] = RelatonBib.array(ret[:copyright]).map do |c|
|
326
|
+
c[:owner] = RelatonBib.array(c[:owner]).map do |o|
|
327
|
+
org_hash_to_bib(o)
|
329
328
|
end
|
329
|
+
c
|
330
330
|
end
|
331
|
+
end
|
331
332
|
|
332
|
-
|
333
|
-
|
334
|
-
|
333
|
+
# @param ret [Hash]
|
334
|
+
def relations_hash_to_bib(ret)
|
335
|
+
return unless ret[:relation]
|
335
336
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
end
|
341
|
-
relation_bibitem_hash_to_bib(r)
|
342
|
-
relation_locality_hash_to_bib(r)
|
343
|
-
relation_source_locality_hash_to_bib(r)
|
337
|
+
ret[:relation] = RelatonBib.array(ret[:relation])
|
338
|
+
ret[:relation]&.each do |r|
|
339
|
+
if r[:description]
|
340
|
+
r[:description] = FormattedString.new(**r[:description])
|
344
341
|
end
|
342
|
+
relation_bibitem_hash_to_bib(r)
|
343
|
+
relation_locality_hash_to_bib(r)
|
344
|
+
relation_source_locality_hash_to_bib(r)
|
345
345
|
end
|
346
|
+
end
|
346
347
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
end
|
348
|
+
# @param rel [Hash] relation
|
349
|
+
def relation_bibitem_hash_to_bib(rel)
|
350
|
+
if rel[:bibitem]
|
351
|
+
rel[:bibitem] = bib_item hash_to_bib(rel[:bibitem])
|
352
|
+
else
|
353
|
+
Util.warn "WARNING: bibitem missing: `#{rel}`"
|
354
|
+
rel[:bibitem] = nil
|
355
355
|
end
|
356
|
+
end
|
356
357
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
358
|
+
# @param item_hash [Hash]
|
359
|
+
# @return [RelatonBib::BibliographicItem]
|
360
|
+
def bib_item(item_hash)
|
361
|
+
BibliographicItem.new(**item_hash)
|
362
|
+
end
|
362
363
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
end
|
364
|
+
# @param rel [Hash] relation
|
365
|
+
# @return [RelatonBib::LocalityStack]
|
366
|
+
def relation_locality_hash_to_bib(rel)
|
367
|
+
rel[:locality] = RelatonBib.array(rel[:locality])&.map do |bl|
|
368
|
+
LocalityStack.new locality_locality_stack(bl)
|
369
369
|
end
|
370
|
+
end
|
370
371
|
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
end
|
377
|
-
else
|
378
|
-
[Locality.new(lls[:type], lls[:reference_from], lls[:reference_to])]
|
372
|
+
def locality_locality_stack(lls)
|
373
|
+
if lls[:locality_stack]
|
374
|
+
RelatonBib.array(lls[:locality_stack]).map do |lc|
|
375
|
+
l = lc[:locality] || lc
|
376
|
+
Locality.new(l[:type], l[:reference_from], l[:reference_to])
|
379
377
|
end
|
378
|
+
else
|
379
|
+
[Locality.new(lls[:type], lls[:reference_from], lls[:reference_to])]
|
380
380
|
end
|
381
|
+
end
|
381
382
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
end
|
390
|
-
else
|
391
|
-
l = SourceLocality.new(sl[:type], sl[:reference_from],
|
392
|
-
sl[:reference_to])
|
393
|
-
[l]
|
383
|
+
# @param rel [Hash] relation
|
384
|
+
def relation_source_locality_hash_to_bib(rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
385
|
+
rel[:source_locality] = RelatonBib.array(rel[:source_locality])&.map do |sl|
|
386
|
+
sls = if sl[:source_locality_stack]
|
387
|
+
RelatonBib.array(sl[:source_locality_stack]).map do |l|
|
388
|
+
SourceLocality.new(l[:type], l[:reference_from],
|
389
|
+
l[:reference_to])
|
394
390
|
end
|
395
|
-
|
396
|
-
|
391
|
+
else
|
392
|
+
l = SourceLocality.new(sl[:type], sl[:reference_from],
|
393
|
+
sl[:reference_to])
|
394
|
+
[l]
|
395
|
+
end
|
396
|
+
SourceLocalityStack.new sls
|
397
397
|
end
|
398
|
+
end
|
398
399
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
end
|
407
|
-
s[:abbreviation] &&
|
408
|
-
s[:abbreviation] = localizedstring(s[:abbreviation])
|
409
|
-
Series.new(**s)
|
400
|
+
# @param ret [Hash]
|
401
|
+
def series_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
402
|
+
ret[:series] = RelatonBib.array(ret[:series])&.map do |s|
|
403
|
+
s[:formattedref] && s[:formattedref] = formattedref(s[:formattedref])
|
404
|
+
if s[:title]
|
405
|
+
s[:title] = { content: s[:title] } unless s[:title].is_a?(Hash)
|
406
|
+
s[:title] = typed_title_strig(s[:title])
|
410
407
|
end
|
408
|
+
s[:abbreviation] &&
|
409
|
+
s[:abbreviation] = localizedstring(s[:abbreviation])
|
410
|
+
Series.new(**s)
|
411
411
|
end
|
412
|
+
end
|
412
413
|
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
414
|
+
# @param title [Hash]
|
415
|
+
# @return [RelatonBib::TypedTitleString]
|
416
|
+
def typed_title_strig(title)
|
417
|
+
TypedTitleString.new(**title)
|
418
|
+
end
|
418
419
|
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
420
|
+
# @param ret [Hash]
|
421
|
+
def medium_hash_to_bib(ret)
|
422
|
+
ret[:medium] = Medium.new(**ret[:medium]) if ret[:medium]
|
423
|
+
end
|
423
424
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
end
|
425
|
+
# @param ret [Hash]
|
426
|
+
def classification_hash_to_bib(ret)
|
427
|
+
if ret[:classification]
|
428
|
+
ret[:classification] = RelatonBib.array(ret[:classification]).map do |cls|
|
429
|
+
Classification.new(**cls)
|
430
430
|
end
|
431
431
|
end
|
432
|
+
end
|
432
433
|
|
433
|
-
|
434
|
-
|
435
|
-
|
434
|
+
# @param ret [Hash]
|
435
|
+
def validity_hash_to_bib(ret)
|
436
|
+
return unless ret[:validity]
|
436
437
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
438
|
+
b = parse_validity_time(ret[:validity], :begins)
|
439
|
+
e = parse_validity_time(ret[:validity], :ends)
|
440
|
+
r = parse_validity_time(ret[:validity], :revision)
|
441
|
+
ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
|
442
|
+
end
|
442
443
|
|
443
|
-
|
444
|
-
|
445
|
-
|
444
|
+
def parse_validity_time(val, period)
|
445
|
+
t = val[period]&.to_s
|
446
|
+
return unless t
|
446
447
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
end
|
448
|
+
p = period == :ends ? -1 : 1
|
449
|
+
case t
|
450
|
+
when /^\d{4}$/
|
451
|
+
Date.new(t.to_i, p, p).to_time
|
452
|
+
when /^(?<year>\d{4})-(?<month>\d{1,2})$/
|
453
|
+
Date.new($~[:year].to_i, $~[:month].to_i, p).to_time
|
454
|
+
else Time.parse t
|
455
455
|
end
|
456
|
+
end
|
456
457
|
|
457
|
-
|
458
|
-
|
459
|
-
|
458
|
+
# @param ret [Hash]
|
459
|
+
def editorialgroup_hash_to_bib(ret)
|
460
|
+
return unless ret[:editorialgroup]
|
460
461
|
|
461
|
-
|
462
|
-
|
463
|
-
end
|
464
|
-
ret[:editorialgroup] = EditorialGroup.new technical_committee
|
462
|
+
technical_committee = RelatonBib.array(ret[:editorialgroup]).map do |wg|
|
463
|
+
TechnicalCommittee.new WorkGroup.new(**wg)
|
465
464
|
end
|
465
|
+
ret[:editorialgroup] = EditorialGroup.new technical_committee
|
466
|
+
end
|
466
467
|
|
467
|
-
|
468
|
-
|
469
|
-
|
468
|
+
# @param ret [Hash]
|
469
|
+
def ics_hash_to_bib(ret)
|
470
|
+
return unless ret[:ics]
|
470
471
|
|
471
|
-
|
472
|
-
|
472
|
+
ret[:ics] = RelatonBib.array(ret[:ics]).map { |ics| ICS.new(**ics) }
|
473
|
+
end
|
473
474
|
|
474
|
-
|
475
|
-
|
476
|
-
|
475
|
+
# @param ret [Hash]
|
476
|
+
def structuredidentifier_hash_to_bib(ret)
|
477
|
+
return unless ret[:structuredidentifier]
|
477
478
|
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
end
|
482
|
-
ret[:structuredidentifier] = StructuredIdentifierCollection.new sids
|
479
|
+
sids = RelatonBib.array(ret[:structuredidentifier]).map do |si|
|
480
|
+
si[:agency] = RelatonBib.array si[:agency]
|
481
|
+
StructuredIdentifier.new(**si)
|
483
482
|
end
|
483
|
+
ret[:structuredidentifier] = StructuredIdentifierCollection.new sids
|
484
|
+
end
|
484
485
|
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
end
|
494
|
-
when Array then obj.reduce([]) { |memo, v| memo << symbolize(v) }
|
495
|
-
else obj
|
486
|
+
# @param ogj [Hash, Array, String]
|
487
|
+
# @return [Hash, Array, String]
|
488
|
+
def symbolize(obj)
|
489
|
+
case obj
|
490
|
+
when Hash
|
491
|
+
obj.reduce({}) do |memo, (k, v)|
|
492
|
+
memo[k.to_sym] = symbolize(v)
|
493
|
+
memo
|
496
494
|
end
|
495
|
+
when Array then obj.reduce([]) { |memo, v| memo << symbolize(v) }
|
496
|
+
else obj
|
497
497
|
end
|
498
|
+
end
|
498
499
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
500
|
+
# @param lst [Hash, Array<RelatonBib::LocalizedString>, String]
|
501
|
+
# @return [RelatonBib::LocalizedString]
|
502
|
+
def localizedstring(lst)
|
503
|
+
return unless lst
|
503
504
|
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
end
|
505
|
+
if lst.is_a?(Hash)
|
506
|
+
LocalizedString.new(lst[:content], lst[:language], lst[:script])
|
507
|
+
else LocalizedString.new(lst)
|
508
508
|
end
|
509
|
+
end
|
509
510
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
end
|
511
|
+
# @param frf [Hash, String]
|
512
|
+
# @return [RelatonBib::FormattedRef]
|
513
|
+
def formattedref(frf)
|
514
|
+
if frf.is_a?(Hash)
|
515
|
+
RelatonBib::FormattedRef.new(**frf)
|
516
|
+
else
|
517
|
+
RelatonBib::FormattedRef.new(content: frf)
|
518
518
|
end
|
519
519
|
end
|
520
|
+
|
521
|
+
def doctype_hash_to_bib(ret)
|
522
|
+
return unless ret[:doctype]
|
523
|
+
|
524
|
+
ret[:doctype] = if ret[:doctype].is_a?(String)
|
525
|
+
create_doctype(type: ret[:doctype])
|
526
|
+
else create_doctype(**ret[:doctype])
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
def create_doctype(**args)
|
531
|
+
DocumentType.new(**args)
|
532
|
+
end
|
520
533
|
end
|
521
534
|
end
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -63,7 +63,7 @@ module RelatonBib
|
|
63
63
|
keyword: bibitem.xpath("keyword").map(&:text),
|
64
64
|
license: bibitem.xpath("license").map(&:text),
|
65
65
|
validity: fetch_validity(bibitem),
|
66
|
-
doctype: ext
|
66
|
+
doctype: fetch_doctype(ext),
|
67
67
|
subdoctype: ext&.at("subdoctype")&.text,
|
68
68
|
editorialgroup: fetch_editorialgroup(ext),
|
69
69
|
ics: fetch_ics(ext),
|
@@ -274,6 +274,13 @@ module RelatonBib
|
|
274
274
|
Validity.new begins: begins, ends: ends, revision: revision
|
275
275
|
end
|
276
276
|
|
277
|
+
def fetch_doctype(ext)
|
278
|
+
dt = ext&.at("doctype")
|
279
|
+
return unless dt
|
280
|
+
|
281
|
+
DocumentType.new type: dt.text, abbreviation: dt[:abbreviation]
|
282
|
+
end
|
283
|
+
|
277
284
|
# @param item [Nokogiri::XML::Element]
|
278
285
|
# @return [Array<RelatonBib::DocumentIdentifier>]
|
279
286
|
def fetch_docid(item)
|
data/lib/relaton_bib.rb
CHANGED
@@ -9,6 +9,7 @@ require "relaton_bib/localized_string"
|
|
9
9
|
require "relaton_bib/forename"
|
10
10
|
require "relaton_bib/full_name"
|
11
11
|
require "relaton_bib/contributor"
|
12
|
+
require "relaton_bib/document_type"
|
12
13
|
require "relaton_bib/bibliographic_item"
|
13
14
|
require "relaton_bib/hit_collection"
|
14
15
|
require "relaton_bib/hit"
|
data/relaton-bib.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-bib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.17.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: 2023-11-
|
11
|
+
date: 2023-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.
|
75
|
+
version: 1.15.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.
|
82
|
+
version: 1.15.0
|
83
83
|
description: 'RelatonBib: Ruby XMLDOC impementation.'
|
84
84
|
email:
|
85
85
|
- open.source@ribose.com
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/relaton_bib/document_relation.rb
|
128
128
|
- lib/relaton_bib/document_relation_collection.rb
|
129
129
|
- lib/relaton_bib/document_status.rb
|
130
|
+
- lib/relaton_bib/document_type.rb
|
130
131
|
- lib/relaton_bib/edition.rb
|
131
132
|
- lib/relaton_bib/editorial_group.rb
|
132
133
|
- lib/relaton_bib/forename.rb
|