relaton-bib 1.13.12 → 1.13.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6ddb62c2750bc1f862980dfbe3c66e6e97db50b00550c794e1a9366265854e2
4
- data.tar.gz: b170e48789567d8b97cb8f969a3afa6785e52ff5e0883a34f80ff09e52884cda
3
+ metadata.gz: 671f76b734663b36559289a0032f01224de697050deb9d46e151ee5542a8ed86
4
+ data.tar.gz: bdf85c3bb18e8e10f88ea50d887af27ed8db08721b2ca4ce070279bbb69ba818
5
5
  SHA512:
6
- metadata.gz: 3a6125762169389c71b9c51ebc27e5a180d66281e5e634584167b3d210b129ae4771a4c624e12b4a90e4318da0278a4e6279e2926298a6026d549b69fe5b3497
7
- data.tar.gz: 2fa41a845a293c0e8cc6ab5bd4720906b59290a700349c03a6af4d705610ddb9d4b115d8726d7de634f8421b569d8091a8e6c05530747f5f0fa79552cc56fe23
6
+ metadata.gz: 0c3e2181a16ad426ad10fb67cb2e2dbf87ba768866fbc17e7858f6692b1bf412a6b68679bf3803da1c41f9ccc97999d6d731d601a47676826ff4e49ce380aada
7
+ data.tar.gz: 3fbbfdad0615432ed971aabb7c2bd61b6cdc3739676aae090453fd2fd3a4674fa773e7a6958b681a65ee853704181f45e5e71746a896cdc95e6f4752a6af29ef
@@ -8,65 +8,74 @@ module RelatonBib
8
8
  # @return [Array<String>]
9
9
  attr_reader :street
10
10
 
11
- # @return [String]
12
- attr_reader :city
13
-
14
- # @return [String, NilClass]
15
- attr_reader :state
16
-
17
- # @return [String]
18
- attr_reader :country
19
-
20
- # @return [String, NilClass]
21
- attr_reader :postcode
11
+ # @return [String, nil]
12
+ attr_reader :city, :state, :country, :postcode, :formatted_address
13
+
14
+ # @param street [Array<String>] streets
15
+ # @param city [String, nil] city, should be present or formatted address provided
16
+ # @param state [String, nil] state
17
+ # @param country [String, nil] country, should be present or formatted address provided
18
+ # @param postcode [String, nil] postcode
19
+ # @param formatted_address [String, nil] formatted address, should be present or city and country provided
20
+ def initialize(**args) # rubocop:disable Metrics/CyclomaticComplexity
21
+ unless args[:formatted_address] || (args[:city] && args[:country])
22
+ raise ArgumentError, "Either formatted address or city and country must be provided"
23
+ end
22
24
 
23
- # @param street [Array<String>]
24
- # @param city [String]
25
- # @param state [String]
26
- # @param country [String]
27
- # @param postcode [String]
28
- def initialize(street:, city:, country:, state: nil, postcode: nil)
29
- @street = street
30
- @city = city
31
- @state = state
32
- @country = country
33
- @postcode = postcode
25
+ @street = args[:street] || []
26
+ @city = args[:city]
27
+ @state = args[:state]
28
+ @country = args[:country]
29
+ @postcode = args[:postcode]
30
+ @formatted_address = args[:formatted_address] unless args[:city] && args[:country]
34
31
  end
35
32
 
36
- # @param builder [Nokogiri::XML::Document]
37
- def to_xml(doc)
33
+ # @param doc [Nokogiri::XML::Document]
34
+ def to_xml(doc) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
38
35
  doc.address do
39
- street.each { |str| doc.street str }
40
- doc.city city
41
- doc.state state if state
42
- doc.country country
43
- doc.postcode postcode if postcode
36
+ if formatted_address
37
+ doc.formattedAddress formatted_address
38
+ else
39
+ street.each { |str| doc.street str }
40
+ doc.city city
41
+ doc.state state if state
42
+ doc.country country
43
+ doc.postcode postcode if postcode
44
+ end
44
45
  end
45
46
  end
46
47
 
47
48
  # @return [Hash]
48
- def to_hash # rubocop:disable Metrics/AbcSize
49
+ def to_hash # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
49
50
  hash = { "address" => {} }
50
- hash["address"]["street"] = street if street&.any?
51
- hash["address"]["city"] = city
52
- hash["address"]["state"] = state if state
53
- hash["address"]["country"] = country
54
- hash["address"]["postcode"] = postcode if postcode
51
+ if formatted_address
52
+ hash["address"]["formatted_address"] = formatted_address
53
+ else
54
+ hash["address"]["street"] = street if street.any?
55
+ hash["address"]["city"] = city
56
+ hash["address"]["state"] = state if state
57
+ hash["address"]["country"] = country
58
+ hash["address"]["postcode"] = postcode if postcode
59
+ end
55
60
  hash
56
61
  end
57
62
 
58
63
  # @param prefix [String]
59
64
  # @param count [Integer] number of addresses
60
65
  # @return [String]
61
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
66
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
62
67
  pref = prefix.empty? ? "address" : "#{prefix}.address"
63
- out = count > 1 ? "#{pref}::\n" : ""
64
- street.each { |st| out += "#{pref}.street:: #{st}\n" }
65
- out += "#{pref}.city:: #{city}\n"
66
- out += "#{pref}.state:: #{state}\n" if state
67
- out += "#{pref}.country:: #{country}\n"
68
- out += "#{pref}.postcode:: #{postcode}\n" if postcode
69
- out
68
+ if formatted_address
69
+ "#{pref}.formatted_address:: #{formatted_address}\n"
70
+ else
71
+ out = count > 1 ? "#{pref}::\n" : ""
72
+ street.each { |st| out += "#{pref}.street:: #{st}\n" }
73
+ out += "#{pref}.city:: #{city}\n"
74
+ out += "#{pref}.state:: #{state}\n" if state
75
+ out += "#{pref}.country:: #{country}\n"
76
+ out += "#{pref}.postcode:: #{postcode}\n" if postcode
77
+ out
78
+ end
70
79
  end
71
80
  end
72
81
 
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.13.12".freeze
2
+ VERSION = "1.13.13".freeze
3
3
  end
@@ -3,6 +3,13 @@ require "nokogiri"
3
3
  module RelatonBib
4
4
  class XMLParser
5
5
  class << self
6
+ #
7
+ # Parse XML bibdata
8
+ #
9
+ # @param [String] xml XML string
10
+ #
11
+ # @return [RelatonBib::BibliographicItem, nil] bibliographic item
12
+ #
6
13
  def from_xml(xml)
7
14
  doc = Nokogiri::XML(xml)
8
15
  doc.remove_namespaces!
@@ -17,10 +24,14 @@ module RelatonBib
17
24
 
18
25
  private
19
26
 
20
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
21
-
22
- # @return [Hash]
23
- def item_data(bibitem) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
27
+ #
28
+ # Parse bibitem data
29
+ #
30
+ # @param bibitem [Nokogiri::XML::Element] bibitem element
31
+ #
32
+ # @return [Hash] bibitem data
33
+ #
34
+ def item_data(bibitem) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
24
35
  ext = bibitem.at "//ext"
25
36
  {
26
37
  id: bibitem[:id].nil? || bibitem[:id].empty? ? nil : bibitem[:id],
@@ -59,8 +70,14 @@ module RelatonBib
59
70
  structuredidentifier: fetch_structuredidentifier(ext),
60
71
  }
61
72
  end
62
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
63
73
 
74
+ #
75
+ # Fetch version.
76
+ #
77
+ # @param [Nokogiri::XML::Elemetn] item bibitem element
78
+ #
79
+ # @return [Array<RelatonBib::BibliographicItem::Version>] versions
80
+ #
64
81
  def fetch_version(item)
65
82
  item.xpath("./version").map do |v|
66
83
  revision_date = v.at("revision-date")&.text
@@ -69,6 +86,13 @@ module RelatonBib
69
86
  end
70
87
  end
71
88
 
89
+ #
90
+ # Fetch edition
91
+ #
92
+ # @param [Nokogiri::XML::Elemetn] item bibitem element
93
+ #
94
+ # @return [RelatonBib::Edition, nil] edition
95
+ #
72
96
  def fetch_edition(item)
73
97
  edt = item.at("./edition")
74
98
  return unless edt
@@ -76,6 +100,13 @@ module RelatonBib
76
100
  Edition.new content: edt.text, number: edt[:number]
77
101
  end
78
102
 
103
+ #
104
+ # Fetch place.
105
+ #
106
+ # @param [Nokogiri::XML::Element] item bibitem element
107
+ #
108
+ # @return [Array<RelatonBib::Place>] array of places
109
+ #
79
110
  def fetch_place(item)
80
111
  item.xpath("./place").map do |pl|
81
112
  if (city = pl.at("./city"))
@@ -114,18 +145,39 @@ module RelatonBib
114
145
  BiblioNoteCollection.new bnotes
115
146
  end
116
147
 
148
+ #
149
+ # Fetch language
150
+ #
151
+ # @param [Nokogiri::XML::Element] item bibitem element
152
+ #
153
+ # @return [Array<String>] language en, fr, etc.
154
+ #
117
155
  def fetch_language(item)
118
156
  item.xpath("./language").reduce([]) do |a, l|
119
157
  l.text.empty? ? a : a << l.text
120
158
  end
121
159
  end
122
160
 
161
+ #
162
+ # Fetch script
163
+ #
164
+ # @param [Nokogiri::XML::Element] item XML element
165
+ #
166
+ # @return [Array<String>] scripts Latn, Cyr, etc.
167
+ #
123
168
  def fetch_script(item)
124
169
  item.xpath("./script").reduce([]) do |a, s|
125
170
  s.text.empty? ? a : a << s.text
126
171
  end
127
172
  end
128
173
 
174
+ #
175
+ # Fetch series
176
+ #
177
+ # @param [Nokogiri::XML::Element] item bibitem element
178
+ #
179
+ # @return [Array<RelatonBib::Series>] series
180
+ #
129
181
  def fetch_series(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/MethodLength,Metrics/PerceivedComplexity
130
182
  item.xpath("./series").reduce([]) do |mem, sr|
131
183
  abbr = sr.at "abbreviation"
@@ -146,6 +198,13 @@ module RelatonBib
146
198
  end
147
199
  end
148
200
 
201
+ #
202
+ # Fetch medium
203
+ #
204
+ # @param [Nokogiri::XML::Element] item item element
205
+ #
206
+ # @return [RelatonBib::Medium, nil] medium
207
+ #
149
208
  def fetch_medium(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
150
209
  medium = item.at("./medium")
151
210
  return unless medium
@@ -157,12 +216,26 @@ module RelatonBib
157
216
  )
158
217
  end
159
218
 
219
+ #
220
+ # Fetch extent
221
+ #
222
+ # @param [Nokogiri::XML::Element] item item element
223
+ #
224
+ # @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>] extent
225
+ #
160
226
  def fetch_extent(item)
161
227
  item.xpath("./extent").reduce([]) do |a, ex|
162
228
  a + localities(ex)
163
229
  end
164
230
  end
165
231
 
232
+ #
233
+ # Fetch size
234
+ #
235
+ # @param [Nokogiri::XML::Element] item item element
236
+ #
237
+ # @return [RelatonBib::BibliographicSize, nil] size
238
+ #
166
239
  def fetch_size(item)
167
240
  size = item.xpath("./size/value").map do |sz|
168
241
  BibliographicSize::Value.new type: sz[:type], value: sz.text
@@ -170,12 +243,26 @@ module RelatonBib
170
243
  BibliographicSize.new size if size.any?
171
244
  end
172
245
 
246
+ #
247
+ # Fetch classification
248
+ #
249
+ # @param [Nokogiri::XML::Element] item bibitem element
250
+ #
251
+ # @return [Array<RelatonBib::Classification>] classifications
252
+ #
173
253
  def fetch_classification(item)
174
254
  item.xpath("classification").map do |cls|
175
255
  Classification.new type: cls[:type], value: cls.text
176
256
  end
177
257
  end
178
258
 
259
+ #
260
+ # Parse validity
261
+ #
262
+ # @param [Nokogiri::XML::Element] item bibitem element
263
+ #
264
+ # @return [RelatonBib::Validity, nil] validity
265
+ #
179
266
  def fetch_validity(item)
180
267
  vl = item.at("./validity")
181
268
  return unless vl
@@ -228,6 +315,13 @@ module RelatonBib
228
315
  end
229
316
  end
230
317
 
318
+ #
319
+ # Parse status
320
+ #
321
+ # @param [Nokogiri::XML::Element] item XML element
322
+ #
323
+ # @return [RelatonBib::DocumentStatus, nil] status
324
+ #
231
325
  def fetch_status(item)
232
326
  status = item.at("./status")
233
327
  return unless status
@@ -264,6 +358,13 @@ module RelatonBib
264
358
  end
265
359
  end
266
360
 
361
+ #
362
+ # Parse organization
363
+ #
364
+ # @param [Nokogiri::XML::Element] org XML element
365
+ #
366
+ # @return [RelatonBib::Organization] organization
367
+ #
267
368
  def get_org(org) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
268
369
  names = org.xpath("name").map do |n|
269
370
  { content: n.text, language: n[:language], script: n[:script] }
@@ -280,6 +381,13 @@ module RelatonBib
280
381
  )
281
382
  end
282
383
 
384
+ #
385
+ # Parse person from XML
386
+ #
387
+ # @param [Nokogiri::XML::Element] person XML element
388
+ #
389
+ # @return [RelatonBib::Person] person
390
+ #
283
391
  def get_person(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
284
392
  affiliations = person.xpath("./affiliation").map do |a|
285
393
  org = a.at "./organization"
@@ -316,23 +424,46 @@ module RelatonBib
316
424
  )
317
425
  end
318
426
 
319
- def parse_contact(contrib) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/AbcSize
427
+ #
428
+ # Parse contact information
429
+ #
430
+ # @param [Nokogiri::XML::Element] contrib contributor element
431
+ #
432
+ # @return [Array<RelatonBib::Address, RelatonBib::Contact>] contacts
433
+ #
434
+ def parse_contact(contrib)
320
435
  contrib.xpath("./address|./phone|./email|./uri").map do |c|
321
- if c.name == "address"
322
- streets = c.xpath("./street").map(&:text)
323
- Address.new(
324
- street: streets,
325
- city: c.at("./city")&.text,
326
- state: c.at("./state")&.text,
327
- country: c.at("./country")&.text,
328
- postcode: c.at("./postcode")&.text,
329
- )
330
- else
331
- Contact.new(type: c.name, value: c.text)
332
- end
436
+ parse_address(c) || Contact.new(type: c.name, value: c.text)
333
437
  end
334
438
  end
335
439
 
440
+ #
441
+ # Parse address
442
+ #
443
+ # @param [Nokogiri::XML::Element] contact contact element
444
+ #
445
+ # @return [RelatonBib::Address] address
446
+ #
447
+ def parse_address(contact) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
448
+ return unless contact.name == "address"
449
+
450
+ Address.new(
451
+ street: contact.xpath("./street").map(&:text),
452
+ city: contact.at("./city")&.text,
453
+ state: contact.at("./state")&.text,
454
+ country: contact.at("./country")&.text,
455
+ postcode: contact.at("./postcode")&.text,
456
+ formatted_address: contact.at("./formattedAddress")&.text,
457
+ )
458
+ end
459
+
460
+ #
461
+ # Parse initials
462
+ #
463
+ # @param [Nokogiri::XML::Element] person person element
464
+ #
465
+ # @return [RelatonBib::LocalizedString, nil] initials
466
+ #
336
467
  def parse_initials(person)
337
468
  inits = person.at "./name/formatted-initials"
338
469
  return unless inits
@@ -340,6 +471,13 @@ module RelatonBib
340
471
  LocalizedString.new(inits.text, inits[:language], inits[:script])
341
472
  end
342
473
 
474
+ #
475
+ # Parse forename
476
+ #
477
+ # @param [Nokogiri::XML::Element] person person element
478
+ #
479
+ # @return [Array<RelatonBib::Forename>] forenames
480
+ #
343
481
  def parse_forename(person)
344
482
  person.xpath("./name/forename").map do |np|
345
483
  args = np.attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v.to_s }
@@ -348,6 +486,14 @@ module RelatonBib
348
486
  end
349
487
  end
350
488
 
489
+ #
490
+ # Parse name part
491
+ #
492
+ # @param [Nokogiri::XML::Element] person person element
493
+ # @param [String] part name part
494
+ #
495
+ # @return [Array<RelatonBib::LocalizedString>] name parts
496
+ #
351
497
  def name_part(person, part)
352
498
  person.xpath("./name/#{part}").map do |np|
353
499
  LocalizedString.new np.text, np[:language], np[:script]
@@ -429,14 +575,24 @@ module RelatonBib
429
575
  script: d[:script], format: d[:format])
430
576
  end
431
577
 
432
- # @param item_hash [Hash]
433
- # @return [RelatonBib::BibliographicItem]
578
+ #
579
+ # Create bibliographic item
580
+ #
581
+ # @param item_hash [Hash] bibliographic item hash
582
+ #
583
+ # @return [RelatonBib::BibliographicItem] bibliographic item
584
+ #
434
585
  def bib_item(item_hash)
435
586
  BibliographicItem.new(**item_hash)
436
587
  end
437
588
 
438
- # @param rel [Nokogiri::XML::Element]
439
- # @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
589
+ #
590
+ # Parse locality
591
+ #
592
+ # @param rel [Nokogiri::XML::Element] relation element
593
+ #
594
+ # @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>] localities
595
+ #
440
596
  def localities(rel)
441
597
  rel.xpath("./locality|./localityStack").map do |lc|
442
598
  if lc.name == "locality"
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.13.12
4
+ version: 1.13.13
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-10-25 00:00:00.000000000 Z
11
+ date: 2022-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug