relaton-bib 1.2.4 → 1.5.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ubuntu.yml +1 -0
  3. data/.rubocop.yml +2 -2
  4. data/README.adoc +60 -18
  5. data/grammars/isodoc.rng +130 -21
  6. data/grammars/reqt.rng +2 -8
  7. data/lib/relaton_bib.rb +3 -5
  8. data/lib/relaton_bib/bib_item_locality.rb +13 -1
  9. data/lib/relaton_bib/biblio_note.rb +38 -0
  10. data/lib/relaton_bib/biblio_version.rb +12 -0
  11. data/lib/relaton_bib/bibliographic_date.rb +15 -1
  12. data/lib/relaton_bib/bibliographic_item.rb +134 -58
  13. data/lib/relaton_bib/bibtex_parser.rb +16 -15
  14. data/lib/relaton_bib/classification.rb +11 -0
  15. data/lib/relaton_bib/contribution_info.rb +41 -9
  16. data/lib/relaton_bib/contributor.rb +64 -6
  17. data/lib/relaton_bib/copyright_association.rb +21 -6
  18. data/lib/relaton_bib/document_identifier.rb +49 -9
  19. data/lib/relaton_bib/document_relation.rb +16 -6
  20. data/lib/relaton_bib/document_relation_collection.rb +12 -2
  21. data/lib/relaton_bib/document_status.rb +10 -0
  22. data/lib/relaton_bib/editorial_group.rb +14 -0
  23. data/lib/relaton_bib/formatted_ref.rb +7 -0
  24. data/lib/relaton_bib/formatted_string.rb +11 -0
  25. data/lib/relaton_bib/hash_converter.rb +39 -33
  26. data/lib/relaton_bib/hit.rb +10 -6
  27. data/lib/relaton_bib/hit_collection.rb +8 -3
  28. data/lib/relaton_bib/ics.rb +11 -0
  29. data/lib/relaton_bib/localized_string.rb +23 -6
  30. data/lib/relaton_bib/medium.rb +11 -0
  31. data/lib/relaton_bib/organization.rb +49 -18
  32. data/lib/relaton_bib/person.rb +76 -17
  33. data/lib/relaton_bib/place.rb +14 -2
  34. data/lib/relaton_bib/series.rb +25 -4
  35. data/lib/relaton_bib/structured_identifier.rb +30 -0
  36. data/lib/relaton_bib/technical_committee.rb +11 -0
  37. data/lib/relaton_bib/typed_title_string.rb +80 -7
  38. data/lib/relaton_bib/typed_uri.rb +11 -0
  39. data/lib/relaton_bib/validity.rb +11 -0
  40. data/lib/relaton_bib/version.rb +1 -1
  41. data/lib/relaton_bib/workgroup.rb +10 -0
  42. data/lib/relaton_bib/xml_parser.rb +65 -41
  43. metadata +7 -7
@@ -48,11 +48,11 @@ module RelatonBib
48
48
  unless self.class::TYPES.include? type
49
49
  warn "[relaton-bib] WARNING: invalid relation type: #{type}"
50
50
  end
51
- @type = type
52
- @description = description
53
- @locality = locality
51
+ @type = type
52
+ @description = description
53
+ @locality = locality
54
54
  @source_locality = source_locality
55
- @bibitem = bibitem
55
+ @bibitem = bibitem
56
56
  end
57
57
 
58
58
  # rubocop:disable Metrics/AbcSize
@@ -63,7 +63,7 @@ module RelatonBib
63
63
  opts.delete :note
64
64
  builder.relation(type: type) do
65
65
  builder.description { description.to_xml builder } if description
66
- bibitem.to_xml(builder, **opts.merge(embedded: true))
66
+ bibitem.to_xml(**opts.merge(builder: builder, embedded: true))
67
67
  locality.each { |l| l.to_xml builder }
68
68
  source_locality.each { |l| l.to_xml builder }
69
69
  end
@@ -71,7 +71,7 @@ module RelatonBib
71
71
  # rubocop:enable Metrics/AbcSize
72
72
 
73
73
  # @return [Hash]
74
- def to_hash
74
+ def to_hash # rubocop:disable Metrics/AbcSize
75
75
  hash = { "type" => type, "bibitem" => bibitem.to_hash }
76
76
  hash["description"] = description.to_hash if description
77
77
  hash["locality"] = single_element_array(locality) if locality&.any?
@@ -80,5 +80,15 @@ module RelatonBib
80
80
  end
81
81
  hash
82
82
  end
83
+
84
+ # @param prefix [String]
85
+ # @return [String]
86
+ def to_asciibib(prefix = "")
87
+ pref = prefix.empty? ? prefix : prefix + "."
88
+ out = "#{prefix}.type:: #{type}\n"
89
+ out += description.to_asciibib "#{pref}desctiption" if description
90
+ out += bibitem.to_asciibib "#{pref}bibitem" if bibitem
91
+ out
92
+ end
83
93
  end
84
94
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "forwardable"
4
-
5
3
  module RelatonBib
6
4
  # Document relation collection
7
5
  class DocRelationCollection
@@ -30,5 +28,17 @@ module RelatonBib
30
28
  def replaces
31
29
  DocRelationCollection.new(@array.select { |r| r.type == "replace" })
32
30
  end
31
+
32
+ # @param prefix [String]
33
+ # @return [String]
34
+ def to_asciibib(prefix = "")
35
+ pref = prefix.empty? ? "relation" : prefix + ".relation"
36
+ out = ""
37
+ @array.each do |r|
38
+ out += size > 1 ? "#{pref}::\n" : ""
39
+ out += r.to_asciibib pref
40
+ end
41
+ out
42
+ end
33
43
  end
34
44
  end
@@ -41,6 +41,16 @@ module RelatonBib
41
41
  hash
42
42
  end
43
43
 
44
+ # @param prefix [String]
45
+ # @return [String]
46
+ def to_asciibib(prefix = "")
47
+ pref = prefix.empty? ? prefix : prefix + "."
48
+ out = "#{pref}docstatus.stage:: #{stage.value}\n"
49
+ out += "#{pref}docstatus.substage:: #{substage.value}\n" if substage
50
+ out += "#{pref}docstatus.iteration:: #{iteration}\n" if iteration
51
+ out
52
+ end
53
+
44
54
  private
45
55
 
46
56
  # @param stg [RelatonBib::DocumentStatus::Stage, Hash, String, NilClass]
@@ -23,5 +23,19 @@ module RelatonBib
23
23
  def to_hash
24
24
  single_element_array technical_committee
25
25
  end
26
+
27
+ # @param prefix [String]
28
+ # @return [String]
29
+ def to_asciibib(prefix = "")
30
+ pref = prefix.empty? ? "editorialgroup" : prefix + ".editorialgroup"
31
+ technical_committee.map do |tc|
32
+ tc.to_asciibib pref, technical_committee.size
33
+ end.join
34
+ end
35
+
36
+ # @return [true]
37
+ def presence?
38
+ true
39
+ end
26
40
  end
27
41
  end
@@ -6,5 +6,12 @@ module RelatonBib
6
6
  def to_xml(builder)
7
7
  builder.formattedref { super }
8
8
  end
9
+
10
+ # @param prefix [String]
11
+ # @return [String]
12
+ def to_asciibib(prefix = "")
13
+ pref = prefix.empty? ? "formattedref" : prefix + ".formattedref"
14
+ super pref
15
+ end
9
16
  end
10
17
  end
@@ -40,5 +40,16 @@ module RelatonBib
40
40
  hash["format"] = format
41
41
  hash
42
42
  end
43
+
44
+ # @param prefix [String]
45
+ # @param count [Integer] number of elements
46
+ # @return [String]
47
+ def to_asciibib(prefix = "", count = 1)
48
+ pref = prefix.empty? ? prefix : prefix + "."
49
+ # out = count > 1 ? "#{prefix}::\n" : ""
50
+ out = super
51
+ out += "#{pref}format:: #{format}\n" if format
52
+ out
53
+ end
43
54
  end
44
55
  end
@@ -4,7 +4,7 @@ module RelatonBib
4
4
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
5
5
 
6
6
  # @param args [Hash]
7
- # @param neated [TrueClas, FalseClass] default true
7
+ # @param neated [TrueClas, FalseClass] default false
8
8
  # @return [Hash]
9
9
  def hash_to_bib(args, nested = false)
10
10
  return nil unless args.is_a?(Hash)
@@ -58,12 +58,11 @@ module RelatonBib
58
58
  def title_hash_to_bib(ret)
59
59
  return unless ret[:title]
60
60
 
61
- ret[:title] = array(ret[:title]).reduce([]) do |m, t|
61
+ ret[:title] = array(ret[:title])
62
+ .reduce(TypedTitleStringCollection.new) do |m, t|
62
63
  if t.is_a?(Hash) then m << t
63
64
  else
64
65
  m + TypedTitleString.from_string(t)
65
- # { content: t, language: "en", script: "Latn", format: "text/plain",
66
- # type: "main" }
67
66
  end
68
67
  end
69
68
  end
@@ -127,7 +126,8 @@ module RelatonBib
127
126
  ret[:docid] = array(ret[:docid])
128
127
  ret[:docid]&.each_with_index do |id, i|
129
128
  type = id[:type] || id[:id].match(/^\w+/)&.to_s
130
- ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: type)
129
+ ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: type,
130
+ scope: id[:scope])
131
131
  end
132
132
  end
133
133
 
@@ -140,31 +140,27 @@ module RelatonBib
140
140
  )
141
141
  end
142
142
 
143
- def biblionote_hash_to_bib(ret)
143
+ def biblionote_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
144
144
  return unless ret[:biblionote]
145
145
 
146
146
  ret[:biblionote] = array(ret[:biblionote])
147
- (ret[:biblionote])&.each_with_index do |n, i|
148
- ret[:biblionote][i] = if n.is_a?(String)
149
- BiblioNote.new content: n
150
- else
151
- BiblioNote.new(
152
- content: n[:content], type: n[:type], language: n[:language],
153
- script: n[:script], format: n[:format]
154
- )
155
- end
147
+ .reduce(BiblioNoteCollection.new([])) do |mem, n|
148
+ mem << if n.is_a?(String) then BiblioNote.new content: n
149
+ else BiblioNote.new(n)
150
+ end
156
151
  end
157
152
  end
158
153
 
159
154
  def formattedref_hash_to_bib(ret)
160
- ret[:formattedref] && ret[:formattedref] = formattedref(ret[:formattedref])
155
+ ret[:formattedref] &&
156
+ ret[:formattedref] = formattedref(ret[:formattedref])
161
157
  end
162
158
 
163
159
  def docstatus_hash_to_bib(ret)
164
160
  ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
165
161
  stage: stage(ret[:docstatus][:stage]),
166
162
  substage: stage(ret[:docstatus][:substage]),
167
- iteration: ret[:docstatus][:iteration],
163
+ iteration: ret[:docstatus][:iteration]
168
164
  )
169
165
  end
170
166
 
@@ -177,7 +173,7 @@ module RelatonBib
177
173
  DocumentStatus::Stage.new(**args)
178
174
  end
179
175
 
180
- def contributors_hash_to_bib(ret)
176
+ def contributors_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
181
177
  return unless ret[:contributor]
182
178
 
183
179
  ret[:contributor] = array(ret[:contributor])
@@ -208,6 +204,9 @@ module RelatonBib
208
204
  org[:identifier] = array(org[:identifier])&.map do |a|
209
205
  OrgIdentifier.new(a[:type], a[:id])
210
206
  end
207
+ org[:subdivision] = array(org[:subdivision]).map do |sd|
208
+ LocalizedString.new sd
209
+ end
211
210
  org
212
211
  end
213
212
 
@@ -216,11 +215,11 @@ module RelatonBib
216
215
  name: fullname_hash_to_bib(person),
217
216
  affiliation: affiliation_hash_to_bib(person),
218
217
  contact: contacts_hash_to_bib(person),
219
- identifier: person_identifiers_hash_to_bib(person),
218
+ identifier: person_identifiers_hash_to_bib(person)
220
219
  )
221
220
  end
222
221
 
223
- def fullname_hash_to_bib(person)
222
+ def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
224
223
  n = person[:name]
225
224
  FullName.new(
226
225
  forename: array(n[:forename])&.map { |f| localname(f, person) },
@@ -228,7 +227,7 @@ module RelatonBib
228
227
  addition: array(n[:addition])&.map { |f| localname(f, person) },
229
228
  prefix: array(n[:prefix])&.map { |f| localname(f, person) },
230
229
  surname: localname(n[:surname], person),
231
- completename: localname(n[:completename], person),
230
+ completename: localname(n[:completename], person)
232
231
  )
233
232
  end
234
233
 
@@ -238,7 +237,7 @@ module RelatonBib
238
237
  end
239
238
  end
240
239
 
241
- def affiliation_hash_to_bib(person)
240
+ def affiliation_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
242
241
  return [] unless person[:affiliation]
243
242
 
244
243
  array(person[:affiliation]).map do |a|
@@ -252,12 +251,12 @@ module RelatonBib
252
251
  end
253
252
  Affiliation.new(
254
253
  organization: Organization.new(org_hash_to_bib(a[:organization])),
255
- description: a[:description],
254
+ description: a[:description]
256
255
  )
257
256
  end
258
257
  end
259
258
 
260
- def contacts_hash_to_bib(person)
259
+ def contacts_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
261
260
  return [] unless person[:contact]
262
261
 
263
262
  array(person[:contact]).map do |a|
@@ -315,42 +314,48 @@ module RelatonBib
315
314
 
316
315
  # @param rel [Hash] relation
317
316
  # @return [RelatonBib::LocalityStack]
318
- def relation_locality_hash_to_bib(rel)
317
+ def relation_locality_hash_to_bib(rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
319
318
  rel[:locality] = array(rel[:locality])&.map do |bl|
320
319
  ls = if bl[:locality_stack]
321
320
  array(bl[:locality_stack]).map do |l|
322
321
  Locality.new(l[:type], l[:reference_from], l[:reference_to])
323
322
  end
324
323
  else
325
- [Locality.new(bl[:type], bl[:reference_from], bl[:reference_to])]
324
+ l = Locality.new(bl[:type], bl[:reference_from],
325
+ bl[:reference_to])
326
+ [l]
326
327
  end
327
328
  LocalityStack.new ls
328
329
  end
329
330
  end
330
331
 
331
332
  # @param rel [Hash] relation
332
- def relation_source_locality_hash_to_bib(rel)
333
+ def relation_source_locality_hash_to_bib(rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
333
334
  rel[:source_locality] = array(rel[:source_locality])&.map do |sl|
334
335
  sls = if sl[:source_locality_stack]
335
336
  array(sl[:source_locality_stack]).map do |l|
336
- SourceLocality.new(l[:type], l[:reference_from], l[:reference_to])
337
+ SourceLocality.new(l[:type], l[:reference_from],
338
+ l[:reference_to])
337
339
  end
338
340
  else
339
- [SourceLocality.new(sl[:type], sl[:reference_from], sl[:reference_to])]
341
+ l = SourceLocality.new(sl[:type], sl[:reference_from],
342
+ sl[:reference_to])
343
+ [l]
340
344
  end
341
345
  SourceLocalityStack.new sls
342
346
  end
343
347
  end
344
348
 
345
349
  # @param ret [Hash]
346
- def series_hash_to_bib(ret)
350
+ def series_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
347
351
  ret[:series] = array(ret[:series])&.map do |s|
348
352
  s[:formattedref] && s[:formattedref] = formattedref(s[:formattedref])
349
353
  if s[:title]
350
354
  s[:title] = { content: s[:title] } unless s[:title].is_a?(Hash)
351
355
  s[:title] = typed_title_strig(s[:title])
352
356
  end
353
- s[:abbreviation] && s[:abbreviation] = localizedstring(s[:abbreviation])
357
+ s[:abbreviation] &&
358
+ s[:abbreviation] = localizedstring(s[:abbreviation])
354
359
  Series.new(s)
355
360
  end
356
361
  end
@@ -454,7 +459,7 @@ module RelatonBib
454
459
  # @param name [Hash, String, NilClass]
455
460
  # @param person [Hash]
456
461
  # @return [RelatonBib::LocalizedString]
457
- def localname(name, person)
462
+ def localname(name, person) # rubocop:disable Metrics/CyclomaticComplexity
458
463
  return nil if name.nil?
459
464
 
460
465
  lang = name[:language] if name.is_a?(Hash)
@@ -469,7 +474,8 @@ module RelatonBib
469
474
  # @return [RelatonBib::LocalizedString]
470
475
  def localizedstring(lst)
471
476
  if lst.is_a?(Hash)
472
- RelatonBib::LocalizedString.new(lst[:content], lst[:language], lst[:script])
477
+ RelatonBib::LocalizedString.new(lst[:content], lst[:language],
478
+ lst[:script])
473
479
  else
474
480
  RelatonBib::LocalizedString.new(lst)
475
481
  end
@@ -20,7 +20,7 @@ module RelatonBib
20
20
 
21
21
  # @return [String]
22
22
  def inspect
23
- "<#{self.class}:#{format('%#.14x', object_id << 1)} "\
23
+ "<#{self.class}:#{format('%<id>#.14x', id: object_id << 1)} "\
24
24
  "@text=\"#{@hit_collection&.text}\" "\
25
25
  "@fetched=\"#{!@fetch.nil?}\" "\
26
26
  "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
@@ -31,13 +31,17 @@ module RelatonBib
31
31
  raise "Not implemented"
32
32
  end
33
33
 
34
- # @param builder [Nokogiri::XML::Builder]
35
- def to_xml(builder = nil, **opts)
36
- if builder
37
- fetch.to_xml builder, **opts
34
+ # @param opts [Hash]
35
+ # @option opts [Nokogiri::XML::Builder] :builder XML builder
36
+ # @option opts [Boolean] :bibdata
37
+ # @option opts [String, Symbol] :lang language
38
+ # @return [String] XML
39
+ def to_xml(**opts)
40
+ if opts[:builder]
41
+ fetch.to_xml **opts
38
42
  else
39
43
  builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
40
- fetch.to_xml xml, **opts
44
+ fetch.to_xml **opts.merge(builder: xml)
41
45
  end
42
46
  builder.doc.root.to_xml
43
47
  end
@@ -36,12 +36,17 @@ module RelatonBib
36
36
  self
37
37
  end
38
38
 
39
+ # @param opts [Hash]
40
+ # @option opts [Nokogiri::XML::Builder] :builder XML builder
41
+ # @option opts [Boolean] :bibdata
42
+ # @option opts [String, Symbol] :lang language
43
+ # @return [String] XML
39
44
  def to_xml(**opts)
40
45
  builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
41
46
  xml.documents do
42
47
  @array.each do |hit|
43
48
  hit.fetch
44
- hit.to_xml xml, **opts
49
+ hit.to_xml **opts.merge(builder: xml)
45
50
  end
46
51
  end
47
52
  end
@@ -49,8 +54,8 @@ module RelatonBib
49
54
  end
50
55
 
51
56
  def select(&block)
52
- me = self.deep_dup
53
- array_dup = self.instance_variable_get(:@array).deep_dup
57
+ me = deep_dup
58
+ array_dup = instance_variable_get(:@array).deep_dup
54
59
  me.instance_variable_set(:@array, array_dup)
55
60
  array_dup.select!(&block)
56
61
  me
@@ -22,5 +22,16 @@ module RelatonBib
22
22
  def to_hash
23
23
  { "code" => code, "text" => text }
24
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
25
36
  end
26
37
  end
@@ -17,10 +17,11 @@ module RelatonBib
17
17
  # @param content [String, Array<RelatonBib::LocalizedString>]
18
18
  # @param language [String] language code Iso639
19
19
  # @param script [String] script code Iso15924
20
- def initialize(content, language = nil, script = nil)
21
- unless content.is_a?(String) || content.is_a?(Array) &&
22
- (inv = content.reject { |c| c.is_a?(LocalizedString) || c.is_a?(Hash) }).
23
- none? && content.any?
20
+ def initialize(content, language = nil, script = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
21
+ if content.is_a? Array
22
+ inv = content.reject { |c| c.is_a?(LocalizedString) || c.is_a?(Hash) }
23
+ end
24
+ unless content.is_a?(String) || inv&.none? && content.any?
24
25
  klass = content.is_a?(Array) ? inv.first.class : content.class
25
26
  raise ArgumentError, "invalid LocalizedString content type: #{klass}"
26
27
  end
@@ -48,7 +49,7 @@ module RelatonBib
48
49
  end
49
50
 
50
51
  # @param builder [Nokogiri::XML::Builder]
51
- def to_xml(builder)
52
+ def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
52
53
  return unless content
53
54
 
54
55
  if content.is_a?(Array)
@@ -61,7 +62,7 @@ module RelatonBib
61
62
  end
62
63
 
63
64
  # @return [Hash]
64
- def to_hash
65
+ def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
65
66
  if content.is_a? String
66
67
  return content unless language || script
67
68
 
@@ -72,5 +73,21 @@ module RelatonBib
72
73
  else content.map &:to_hash
73
74
  end
74
75
  end
76
+
77
+ # @param prefix [String]
78
+ # @param count [Integer] number of elements
79
+ # @return [String]
80
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
81
+ pref = prefix.empty? ? prefix : prefix + "."
82
+ if content.is_a? String
83
+ out = count > 1 ? "#{prefix}::\n" : ""
84
+ out += "#{pref}content:: #{content}\n"
85
+ language&.each { |l| out += "#{pref}language:: #{l}\n" }
86
+ script&.each { |s| out += "#{pref}script:: #{s}\n" }
87
+ out
88
+ else
89
+ content.map { |c| c.to_asciibib "#{pref}variant", content.size }.join
90
+ end
91
+ end
75
92
  end
76
93
  end