relaton-bib 0.3.6 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2652e6a30640ef8035238e6ae6126063b9057890
4
- data.tar.gz: 03f6a59bf6dd3d152578073e55d5d35b235bfc34
3
+ metadata.gz: ceddccd39bcf1423b79aa28256b8bdc0cd5d1920
4
+ data.tar.gz: 3f4fb8004a268ebe022e00e989a8f01427f2beb9
5
5
  SHA512:
6
- metadata.gz: 6ead52473fc5af8a5c86d9fce36bc048f383c3740c2047a7fd7bfc26cfd3f6211587842a0a5add6cdc7d1060e4d9d1d6f167b4e20fb751f8482f3c2a53be2e68
7
- data.tar.gz: 540bccaead183468e59e4ea8b3edc64352d1d1df1c12ca6f3a09e4e8f7c3c2f891681490a5f7d548412833dcdc9c05b96839e8a134306b1e464d92041148e863
6
+ metadata.gz: 59f0667f7628db03cb608f784ba64780796b20933d0531607c53ef51c65d5dd3252f493a8831994d706278de517ec0b6416ddcad7b9056f9f0c86c0e543392f1
7
+ data.tar.gz: c5df8ae589ab71e155ef6a51edde861350169528982d673fe450a084132aaa895f7ae4efe627f65ddf67ae41d1c1d5f9d2bd1670f394e01452d453eef98158f3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-bib (0.3.6)
4
+ relaton-bib (0.3.7)
5
5
  addressable
6
6
  nokogiri
7
7
 
@@ -6,8 +6,7 @@ module RelatonBib
6
6
  # Bibliographic date.
7
7
  class BibliographicDate
8
8
  TYPES = %w[published accessed created implemented obsoleted confirmed
9
- updated issued transmitted copied unchanged circulated
10
- ].freeze
9
+ updated issued transmitted copied unchanged circulated adapted].freeze
11
10
 
12
11
  # @return [String]
13
12
  attr_reader :type
@@ -28,7 +27,7 @@ module RelatonBib
28
27
  def initialize(type:, on: nil, from: nil, to: nil)
29
28
  raise ArgumentError, "expected :on or :from argument" unless on || from
30
29
 
31
- raise ArgumentError, "invalid type: #{type}" unless TYPES.include? type
30
+ # raise ArgumentError, "invalid type: #{type}" unless TYPES.include? type
32
31
 
33
32
  @type = type
34
33
  @on = RelatonBib.parse_date on
@@ -169,7 +169,7 @@ module RelatonBib
169
169
  # @option link [String] :content
170
170
  def initialize(**args)
171
171
  if args[:type] && !TYPES.include?(args[:type])
172
- raise ArgumentError, %{Type "#{args[:type]}" is invalid.}
172
+ warn %{Document type "#{args[:type]}" is invalid.}
173
173
  end
174
174
 
175
175
  @title = (args[:title] || []).map do |t|
@@ -13,8 +13,8 @@ module RelatonBib
13
13
  attr_reader :format
14
14
 
15
15
  # @param content [String]
16
- # @param language [String] language code Iso639
17
- # @param script [String] script code Iso15924
16
+ # @param language [String, NilClass] language code Iso639
17
+ # @param script [String, NilClass] script code Iso15924
18
18
  # @param format [String] the content type
19
19
  def initialize(content:, language: nil, script: nil, format: "text/plain")
20
20
  # if format && !FORMATS.include?(format)
@@ -35,6 +35,7 @@ module RelatonBib
35
35
 
36
36
  def extent_hash_to_bib(ret)
37
37
  return unless ret[:extent]
38
+
38
39
  ret[:extent] = array(ret[:extent])
39
40
  ret[:extent]&.each_with_index do |e, i|
40
41
  ret[:extent][i] = BibItemLocality.new(e[:type], e[:reference_from],
@@ -44,45 +45,57 @@ module RelatonBib
44
45
 
45
46
  def title_hash_to_bib(ret)
46
47
  return unless ret[:title]
48
+
47
49
  ret[:title] = array(ret[:title])
48
50
  ret[:title] = ret[:title].map do |t|
49
- t.is_a?(Hash) ? t : { content: t, language: "en", script: "Latn",
50
- format: "text/plain", type: "main" }
51
+ if t.is_a?(Hash) then t
52
+ else
53
+ { content: t, language: "en", script: "Latn", format: "text/plain", type: "main" }
54
+ end
51
55
  end
52
56
  end
53
57
 
54
58
  def language_hash_to_bib(ret)
55
59
  return unless ret[:language]
60
+
56
61
  ret[:language] = array(ret[:language])
57
62
  end
58
63
 
59
64
  def script_hash_to_bib(ret)
60
65
  return unless ret[:script]
66
+
61
67
  ret[:script] = array(ret[:script])
62
68
  end
63
69
 
64
70
  def abstract_hash_to_bib(ret)
65
71
  return unless ret[:abstract]
66
- ret[:abstract] = array(ret[:abstract])
72
+
73
+ ret[:abstract] = array(ret[:abstract]).map do |a|
74
+ a.is_a?(String) ? FormattedString.new(content: a) : a
75
+ end
67
76
  end
68
77
 
69
78
  def link_hash_to_bib(ret)
70
79
  return unless ret[:link]
80
+
71
81
  ret[:link] = array(ret[:link])
72
82
  end
73
83
 
74
84
  def place_hash_to_bib(ret)
75
85
  return unless ret[:place]
86
+
76
87
  ret[:place] = array(ret[:place])
77
88
  end
78
89
 
79
90
  def accesslocation_hash_to_bib(ret)
80
91
  return unless ret[:accesslocation]
92
+
81
93
  ret[:accesslocation] = array(ret[:accesslocation])
82
94
  end
83
95
 
84
96
  def dates_hash_to_bib(ret)
85
97
  return unless ret[:date]
98
+
86
99
  ret[:date] = array(ret[:date])
87
100
  ret[:date].each_with_index do |d, i|
88
101
  # value is synonym of on: it is reserved word in YAML
@@ -95,6 +108,7 @@ module RelatonBib
95
108
 
96
109
  def docid_hash_to_bib(ret)
97
110
  return unless ret[:docid]
111
+
98
112
  ret[:docid] = array(ret[:docid])
99
113
  ret[:docid]&.each_with_index do |id, i|
100
114
  ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: id[:type])
@@ -103,32 +117,35 @@ module RelatonBib
103
117
 
104
118
  def version_hash_to_bib(ret)
105
119
  return unless ret[:version]
120
+
106
121
  ret[:version][:draft] = array(ret[:version][:draft])
107
- ret[:version] and ret[:version] = BibliographicItem::Version.new(
108
- ret[:version][:revision_date], ret[:version][:draft])
122
+ ret[:version] && ret[:version] = BibliographicItem::Version.new(
123
+ ret[:version][:revision_date], ret[:version][:draft]
124
+ )
109
125
  end
110
126
 
111
127
  def biblionote_hash_to_bib(ret)
112
128
  return unless ret[:biblionote]
129
+
113
130
  ret[:biblionote] = array(ret[:biblionote])
114
131
  (ret[:biblionote])&.each_with_index do |n, i|
115
- ret[:biblionote][i] =
116
- BiblioNote.new(content: n[:content], type: n[:type],
117
- language: n[:language],
118
- script: n[:script], format: n[:format])
132
+ ret[:biblionote][i] = BiblioNote.new(
133
+ content: n[:content], type: n[:type], language: n[:language],
134
+ script: n[:script], format: n[:format]
135
+ )
119
136
  end
120
137
  end
121
138
 
122
139
  def formattedref_hash_to_bib(ret)
123
- ret[:formattedref] and ret[:formattedref] =
124
- formattedref(ret[:formattedref])
140
+ ret[:formattedref] && ret[:formattedref] = formattedref(ret[:formattedref])
125
141
  end
126
142
 
127
143
  def docstatus_hash_to_bib(ret)
128
- ret[:docstatus] and ret[:docstatus] =
129
- DocumentStatus.new(stage: ret[:docstatus][:stage],
130
- substage: ret[:docstatus][:substage],
131
- iteration: ret[:docstatus][:iteration])
144
+ ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
145
+ stage: ret[:docstatus][:stage],
146
+ substage: ret[:docstatus][:substage],
147
+ iteration: ret[:docstatus][:iteration],
148
+ )
132
149
  end
133
150
 
134
151
  def contributors_hash_to_bib(ret)
@@ -146,73 +163,83 @@ module RelatonBib
146
163
  end
147
164
  end
148
165
  ret[:contributor][i][:role] = roles
149
- ret[:contributor][i][:entity] = c[:person] ?
150
- person_hash_to_bib(c[:person]) : org_hash_to_bib(c[:organization])
166
+ ret[:contributor][i][:entity] = if c[:person]
167
+ person_hash_to_bib(c[:person])
168
+ else
169
+ org_hash_to_bib(c[:organization])
170
+ end
151
171
  ret[:contributor][i].delete(:person)
152
172
  ret[:contributor][i].delete(:organization)
153
173
  end
154
174
  end
155
175
 
156
- def org_hash_to_bib(c)
157
- return nil if c.nil?
158
- c[:identifier] = array(c[:identifier])&.map do |a|
176
+ def org_hash_to_bib(org)
177
+ return nil if org.nil?
178
+
179
+ org[:identifier] = array(org[:identifier])&.map do |a|
159
180
  OrgIdentifier.new(a[:type], a[:id])
160
181
  end
161
- c
182
+ org
162
183
  end
163
184
 
164
- def person_hash_to_bib(c)
185
+ def person_hash_to_bib(person)
165
186
  Person.new(
166
- name: fullname_hash_to_bib(c),
167
- affiliation: affiliation_hash_to_bib(c),
168
- contact: contacts_hash_to_bib(c),
169
- identifier: person_identifiers_hash_to_bib(c),
187
+ name: fullname_hash_to_bib(person),
188
+ affiliation: affiliation_hash_to_bib(person),
189
+ contact: contacts_hash_to_bib(person),
190
+ identifier: person_identifiers_hash_to_bib(person),
170
191
  )
171
192
  end
172
193
 
173
- def fullname_hash_to_bib(c)
174
- n = c[:name]
194
+ def fullname_hash_to_bib(person)
195
+ n = person[:name]
175
196
  FullName.new(
176
- forename: array(n[:forename])&.map { |f| localname(f, c) },
177
- initial: array(n[:initial])&.map { |f| localname(f, c) },
178
- addition: array(n[:addition])&.map { |f| localname(f, c) },
179
- prefix: array(n[:prefix])&.map { |f| localname(f, c) },
180
- surname: localname(n[:surname], c),
181
- completename: localname(n[:completename], c),
197
+ forename: array(n[:forename])&.map { |f| localname(f, person) },
198
+ initial: array(n[:initial])&.map { |f| localname(f, person) },
199
+ addition: array(n[:addition])&.map { |f| localname(f, person) },
200
+ prefix: array(n[:prefix])&.map { |f| localname(f, person) },
201
+ surname: localname(n[:surname], person),
202
+ completename: localname(n[:completename], person),
182
203
  )
183
204
  end
184
205
 
185
- def person_identifiers_hash_to_bib(c)
186
- array(c[:identifier])&.map do |a|
206
+ def person_identifiers_hash_to_bib(person)
207
+ array(person[:identifier])&.map do |a|
187
208
  PersonIdentifier.new(a[:type], a[:id])
188
209
  end
189
210
  end
190
211
 
191
- def affiliation_hash_to_bib(c)
192
- return [] unless c[:affiliation]
193
- array(c[:affiliation]).map do |a|
212
+ def affiliation_hash_to_bib(person)
213
+ return [] unless person[:affiliation]
214
+
215
+ array(person[:affiliation]).map do |a|
194
216
  a[:description] = array(a[:description])&.map do |d|
195
- FormattedString.new(
196
- d.is_a?(Hash) ?
197
- { content: d[:content], language: d[:language],
198
- script: d[:script], format: d[:format] } :
199
- { content: d })
217
+ cnt = if d.is_a?(Hash)
218
+ { content: d[:content], language: d[:language],
219
+ script: d[:script], format: d[:format] }
220
+ else { content: d }
221
+ end
222
+ FormattedString.new cnt
200
223
  end
201
224
  Affilation.new(
202
225
  organization: Organization.new(org_hash_to_bib(a[:organization])),
203
- description: a[:description]
226
+ description: a[:description],
204
227
  )
205
228
  end
206
229
  end
207
230
 
208
- def contacts_hash_to_bib(c)
209
- return [] unless c[:contact]
210
- array(c[:contact]).map do |a|
211
- (a[:city] || a[:country]) ?
231
+ def contacts_hash_to_bib(person)
232
+ return [] unless person[:contact]
233
+
234
+ array(person[:contact]).map do |a|
235
+ if a[:city] || a[:country]
212
236
  RelatonBib::Address.new(
213
237
  street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
214
- country: a[:country], state: a[:state]) :
215
- RelatonBib::Contact.new(type: a[:type], value: a[:value])
238
+ country: a[:country], state: a[:state]
239
+ )
240
+ else
241
+ RelatonBib::Contact.new(type: a[:type], value: a[:value])
242
+ end
216
243
  end
217
244
  end
218
245
 
@@ -227,14 +254,14 @@ module RelatonBib
227
254
  end
228
255
 
229
256
  # @param ret [Hash]
230
- # @param r [Hash] relation
231
- # @param i [Integr] index of relation
232
- def relation_bibitem_hash_to_bib(ret, r, i)
233
- if r[:bibitem]
234
- ret[:relation][i][:bibitem] = bib_item(hash_to_bib(r[:bibitem], true))
257
+ # @param rel [Hash] relation
258
+ # @param idx [Integr] index of relation
259
+ def relation_bibitem_hash_to_bib(ret, rel, idx)
260
+ if rel[:bibitem]
261
+ ret[:relation][idx][:bibitem] = bib_item(hash_to_bib(rel[:bibitem], true))
235
262
  else
236
- warn "bibitem missing: #{r}"
237
- ret[:relation][i][:bibitem] = nil
263
+ warn "bibitem missing: #{rel}"
264
+ ret[:relation][idx][:bibitem] = nil
238
265
  end
239
266
  end
240
267
 
@@ -244,9 +271,9 @@ module RelatonBib
244
271
  BibliographicItem.new(item)
245
272
  end
246
273
 
247
- def relation_biblocality_hash_to_bib(ret, r, i)
248
- ret[:relation][i][:bib_locality] =
249
- array(r[:bib_locality])&.map do |bl|
274
+ def relation_biblocality_hash_to_bib(ret, rel, idx)
275
+ ret[:relation][idx][:bib_locality] =
276
+ array(rel[:bib_locality])&.map do |bl|
250
277
  BibItemLocality.new(bl[:type], bl[:reference_from],
251
278
  bl[:reference_to])
252
279
  end
@@ -271,7 +298,7 @@ module RelatonBib
271
298
  end
272
299
 
273
300
  def medium_hash_to_bib(ret)
274
- ret[:medium] and ret[:medium] = Medium.new(ret[:medium])
301
+ ret[:medium] = Medium.new(ret[:medium]) if ret[:medium]
275
302
  end
276
303
 
277
304
  def classification_hash_to_bib(ret)
@@ -279,52 +306,70 @@ module RelatonBib
279
306
  # ret[:classification]&.each_with_index do |c, i|
280
307
  # ret[:classification][i] = RelatonBib::Classification.new(c)
281
308
  # end
282
- ret[:classification] and
309
+ if ret[:classification]
283
310
  ret[:classification] = Classification.new(ret[:classification])
311
+ end
284
312
  end
285
313
 
286
314
  def validity_hash_to_bib(ret)
287
315
  return unless ret[:validity]
288
- ret[:validity][:begins] and b = Time.parse(ret[:validity][:begins])
289
- ret[:validity][:ends] and e = Time.parse(ret[:validity][:ends])
290
- ret[:validity][:revision] and r = Time.parse(ret[:validity][:revision])
316
+
317
+ ret[:validity][:begins] && b = Time.parse(ret[:validity][:begins])
318
+ ret[:validity][:ends] && e = Time.parse(ret[:validity][:ends])
319
+ ret[:validity][:revision] && r = Time.parse(ret[:validity][:revision])
291
320
  ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
292
321
  end
293
322
 
323
+ # @param ogj [Hash, Array, String]
324
+ # @return [Hash, Array, String]
294
325
  def symbolize(obj)
295
- obj.is_a? Hash and
296
- return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo}
297
- obj.is_a? Array and
298
- return obj.inject([]){|memo,v | memo << symbolize(v); memo}
299
- return obj
326
+ if obj.is_a? Hash
327
+ obj.reduce({}) do |memo, (k, v)|
328
+ memo[k.to_sym] = symbolize(v)
329
+ memo
330
+ end
331
+ elsif obj.is_a? Array
332
+ obj.reduce([]) { |memo, v| memo << symbolize(v) }
333
+ else
334
+ obj
335
+ end
300
336
  end
301
337
 
302
- def array(a)
303
- return [] unless a
304
- return [a] unless a.is_a?(Array)
305
- a
338
+ def array(arr)
339
+ return [] unless arr
340
+ return [arr] unless arr.is_a?(Array)
341
+
342
+ arr
306
343
  end
307
344
 
308
- def localname(f, c)
309
- return nil if f.nil?
310
- f.is_a?(Hash) and lang = f[:language]
311
- lang ||= c[:name][:language]
312
- f.is_a?(Hash) and script = f[:script]
313
- script ||= c[:name][:script]
314
- f.is_a?(Hash) ?
315
- RelatonBib::LocalizedString.new(f[:content], lang, script) :
316
- RelatonBib::LocalizedString.new(f, lang, script)
345
+ def localname(name, person)
346
+ return nil if name.nil?
347
+
348
+ lang = name[:language] if name.is_a?(Hash)
349
+ lang ||= person[:name][:language]
350
+ script = name[:script] if name.is_a?(Hash)
351
+ script ||= person[:name][:script]
352
+ if name.is_a?(Hash)
353
+ RelatonBib::LocalizedString.new(name[:content], lang, script)
354
+ else
355
+ RelatonBib::LocalizedString.new(name, lang, script)
356
+ end
317
357
  end
318
358
 
319
- def localizedstring(f)
320
- f.is_a?(Hash) ?
321
- RelatonBib::LocalizedString.new(f[:content], f[:language], f[:script]) :
322
- RelatonBib::LocalizedString.new(f)
359
+ def localizedstring(lst)
360
+ if lst.is_a?(Hash)
361
+ RelatonBib::LocalizedString.new(lst[:content], lst[:language], lst[:script])
362
+ else
363
+ RelatonBib::LocalizedString.new(lst)
364
+ end
323
365
  end
324
366
 
325
- def formattedref(f)
326
- f.is_a?(Hash) ? RelatonBib::FormattedRef.new(f) :
327
- RelatonBib::FormattedRef.new(content: f)
367
+ def formattedref(frf)
368
+ if frf.is_a?(Hash)
369
+ RelatonBib::FormattedRef.new(frf)
370
+ else
371
+ RelatonBib::FormattedRef.new(content: frf)
372
+ end
328
373
  end
329
374
  end
330
375
  end
@@ -4,7 +4,7 @@ module RelatonBib
4
4
  attr_reader :hit
5
5
 
6
6
  # @param hit [Hash]
7
- # @param hit_collection [RelatonNist:HitCollection]
7
+ # @param hit_collection [RelatonIso::HitCollection, RelatonNist:HitCollection]
8
8
  def initialize(hit, hit_collection = nil)
9
9
  @hit = hit
10
10
  @hit_collection = hit_collection
@@ -9,7 +9,7 @@ module RelatonBib
9
9
  # @return [String]
10
10
  attr_reader :year
11
11
 
12
- # @return [Iecbib::HitCollection]
12
+ # @return [RelatonIso::HitCollection]
13
13
  def fetch
14
14
  workers = WorkersPool.new 4
15
15
  workers.worker(&:fetch)
@@ -45,9 +45,16 @@ module RelatonBib
45
45
 
46
46
  # @return [Hash]
47
47
  def to_hash
48
- hash = {}
49
- hash["type"] = type if type
50
- hash.merge title.to_hash
48
+ th = title.to_hash
49
+ return th unless type
50
+
51
+ hash = { "type" => type }
52
+ if th.is_a? String
53
+ hash["content"] = th
54
+ else
55
+ hash.merge th
56
+ end
57
+ hash
51
58
  end
52
59
  end
53
60
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "0.3.6".freeze
2
+ VERSION = "0.3.7".freeze
3
3
  end
@@ -5,7 +5,7 @@ module RelatonBib
5
5
  class << self
6
6
  def from_xml(xml)
7
7
  doc = Nokogiri::XML(xml)
8
- bibitem = doc.at "/bibitem"
8
+ bibitem = doc.at "/bibitem|/bibdata"
9
9
  BibliographicItem.new(item_data(bibitem))
10
10
  end
11
11
 
@@ -29,8 +29,8 @@ module RelatonBib
29
29
  edition: bibitem.at("./edition")&.text,
30
30
  version: fetch_version(bibitem),
31
31
  biblionote: fetch_note(bibitem),
32
- language: bibitem.xpath("./language").map(&:text),
33
- script: bibitem.xpath("./script").map(&:text),
32
+ language: fetch_language(bibitem),
33
+ script: fetch_script(bibitem),
34
34
  abstract: fetch_abstract(bibitem),
35
35
  docstatus: fetch_status(bibitem),
36
36
  copyright: fetch_copyright(bibitem),
@@ -67,6 +67,14 @@ module RelatonBib
67
67
  end
68
68
  end
69
69
 
70
+ def fetch_language(item)
71
+ item.xpath("./language").reduce([]) { |a, l| l.text.empty? ? a : a << l.text }
72
+ end
73
+
74
+ def fetch_script(item)
75
+ item.xpath("./script").reduce([]) { |a, s| s.text.empty? ? a : a << s.text }
76
+ end
77
+
70
78
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
71
79
 
72
80
  def fetch_series(item)
@@ -145,8 +153,9 @@ module RelatonBib
145
153
  status = item.at("./status")
146
154
  return unless status
147
155
 
156
+ stage = status.at "stage"
148
157
  DocumentStatus.new(
149
- stage: status.at("stage").text,
158
+ stage: stage ? stage.text : status.text,
150
159
  substage: status.at("substage")&.text,
151
160
  iteration: status.at("iteration")&.text,
152
161
  )
@@ -154,8 +163,9 @@ module RelatonBib
154
163
 
155
164
  def fetch_dates(item)
156
165
  item.xpath("./date").map do |d|
166
+ type = d[:type].to_s.empty? ? "published" : d[:type]
157
167
  RelatonBib::BibliographicDate.new(
158
- type: d[:type], on: d.at("on")&.text, from: d.at("from")&.text,
168
+ type: type, on: d.at("on")&.text, from: d.at("from")&.text,
159
169
  to: d.at("to")&.text
160
170
  )
161
171
  end
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: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-11 00:00:00.000000000 Z
11
+ date: 2019-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler