relaton-bib 1.7.5 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/grammars/reqt.rng CHANGED
@@ -30,15 +30,34 @@
30
30
  <data type="boolean"/>
31
31
  </attribute>
32
32
  </optional>
33
+ <optional>
34
+ <attribute name="number"/>
35
+ </optional>
33
36
  <optional>
34
37
  <attribute name="subsequence"/>
35
38
  </optional>
39
+ <optional>
40
+ <attribute name="keep-with-next">
41
+ <data type="boolean"/>
42
+ </attribute>
43
+ </optional>
44
+ <optional>
45
+ <attribute name="keep-lines-together">
46
+ <data type="boolean"/>
47
+ </attribute>
48
+ </optional>
36
49
  <attribute name="id">
37
50
  <data type="ID"/>
38
51
  </attribute>
39
52
  <optional>
40
53
  <attribute name="filename"/>
41
54
  </optional>
55
+ <optional>
56
+ <attribute name="model"/>
57
+ </optional>
58
+ <optional>
59
+ <attribute name="type"/>
60
+ </optional>
42
61
  <optional>
43
62
  <ref name="reqtitle"/>
44
63
  </optional>
@@ -48,9 +67,9 @@
48
67
  <optional>
49
68
  <ref name="subject"/>
50
69
  </optional>
51
- <optional>
70
+ <zeroOrMore>
52
71
  <ref name="reqinherit"/>
53
- </optional>
72
+ </zeroOrMore>
54
73
  <zeroOrMore>
55
74
  <ref name="classification"/>
56
75
  </zeroOrMore>
@@ -135,6 +154,16 @@
135
154
  <data type="boolean"/>
136
155
  </attribute>
137
156
  </optional>
157
+ <optional>
158
+ <attribute name="keep-with-next">
159
+ <data type="boolean"/>
160
+ </attribute>
161
+ </optional>
162
+ <optional>
163
+ <attribute name="keep-lines-together">
164
+ <data type="boolean"/>
165
+ </attribute>
166
+ </optional>
138
167
  <oneOrMore>
139
168
  <ref name="BasicBlock"/>
140
169
  </oneOrMore>
@@ -44,7 +44,7 @@ module RelatonBib
44
44
  # @param count [Integeg] number of localities
45
45
  # @return [String]
46
46
  def to_asciibib(prefix = "", count = 1)
47
- pref = prefix.empty? ? prefix : prefix + "."
47
+ pref = prefix.empty? ? prefix : "#{prefix}."
48
48
  out = count > 1 ? "#{prefix}::\n" : ""
49
49
  out += "#{pref}type:: #{type}\n"
50
50
  out += "#{pref}reference_from:: #{reference_from}\n"
@@ -7,7 +7,7 @@ module RelatonBib
7
7
  class BibliographicDate
8
8
  TYPES = %w[published accessed created implemented obsoleted confirmed
9
9
  updated issued transmitted copied unchanged circulated adapted
10
- vote-started vote-ended].freeze
10
+ vote-started vote-ended announced].freeze
11
11
 
12
12
  # @return [String]
13
13
  attr_reader :type
@@ -42,7 +42,7 @@ module RelatonBib
42
42
  attr_accessor :all_parts
43
43
 
44
44
  # @return [String, NilClass]
45
- attr_reader :id, :type, :docnumber, :edition, :doctype
45
+ attr_reader :id, :type, :docnumber, :edition, :doctype, :subdoctype
46
46
 
47
47
  # @!attribute [r] title
48
48
  # @return [RelatonBib::TypedTitleStringCollection]
@@ -148,6 +148,7 @@ module RelatonBib
148
148
  # @param fetched [Date, NilClass] default nil
149
149
  # @param keyword [Array<String>]
150
150
  # @param doctype [String]
151
+ # @param subdoctype [String]
151
152
  # @param editorialgroup [RelatonBib::EditorialGroup, nil]
152
153
  # @param ics [Array<RelatonBib::ICS>]
153
154
  # @param structuredidentifier [RelatonBib::StructuredIdentifierCollection]
@@ -229,8 +230,9 @@ module RelatonBib
229
230
  @status = args[:docstatus]
230
231
  @relation = DocRelationCollection.new(args[:relation] || [])
231
232
  @link = args.fetch(:link, []).map do |s|
232
- if s.is_a?(Hash) then TypedUri.new(**s)
233
- elsif s.is_a?(String) then TypedUri.new(content: s)
233
+ case s
234
+ when Hash then TypedUri.new(**s)
235
+ when String then TypedUri.new(content: s)
234
236
  else s
235
237
  end
236
238
  end
@@ -250,6 +252,7 @@ module RelatonBib
250
252
  end
251
253
  @license = args.fetch :license, []
252
254
  @doctype = args[:doctype]
255
+ @subdoctype = args[:subdoctype]
253
256
  @editorialgroup = args[:editorialgroup]
254
257
  @ics = args.fetch :ics, []
255
258
  @structuredidentifier = args[:structuredidentifier]
@@ -260,8 +263,8 @@ module RelatonBib
260
263
  # @param hash [Hash]
261
264
  # @return [RelatonBipm::BipmBibliographicItem]
262
265
  def self.from_hash(hash)
263
- item_hash = ::RelatonBib::HashConverter.hash_to_bib(hash)
264
- new **item_hash
266
+ item_hash = Object.const_get(name.split("::")[0])::HashConverter.hash_to_bib(hash)
267
+ new(**item_hash)
265
268
  end
266
269
 
267
270
  # @param lang [String] language code Iso639
@@ -286,7 +289,7 @@ module RelatonBib
286
289
  # contribs = publishers.map { |p| p&.entity&.abbreviation }.join '/'
287
290
  # idstr = "#{contribs}#{delim}#{id.project_number}"
288
291
  # idstr = id.project_number.to_s
289
- idstr = id.id.gsub(/:/, "-").gsub /\s/, ""
292
+ idstr = id.id.gsub(/:/, "-").gsub(/\s/, "")
290
293
  # if id.part_number&.size&.positive? then idstr += "-#{id.part_number}"
291
294
  idstr.strip
292
295
  end
@@ -299,7 +302,7 @@ module RelatonBib
299
302
  def shortref(identifier, **opts) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
300
303
  pubdate = date.select { |d| d.type == "published" }
301
304
  year = if opts[:no_year] || pubdate.empty? then ""
302
- else ":" + pubdate&.first&.on(:year).to_s
305
+ else ":#{pubdate&.first&.on(:year)}"
303
306
  end
304
307
  year += ": All Parts" if opts[:all_parts] || @all_parts
305
308
 
@@ -314,7 +317,7 @@ module RelatonBib
314
317
  # @return [String] XML
315
318
  def to_xml(**opts, &block)
316
319
  if opts[:builder]
317
- render_xml **opts, &block
320
+ render_xml(**opts, &block)
318
321
  else
319
322
  Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
320
323
  render_xml builder: xml, **opts, &block
@@ -361,6 +364,7 @@ module RelatonBib
361
364
  hash["keyword"] = single_element_array(keyword) if keyword&.any?
362
365
  hash["license"] = single_element_array(license) if license&.any?
363
366
  hash["doctype"] = doctype if doctype
367
+ hash["subdoctype"] = subdoctype if subdoctype
364
368
  if editorialgroup&.presence?
365
369
  hash["editorialgroup"] = editorialgroup.to_hash
366
370
  end
@@ -460,7 +464,7 @@ module RelatonBib
460
464
  me.date = []
461
465
  me.docidentifier.each &:remove_date
462
466
  me.structuredidentifier&.remove_date
463
- me.id&.sub! /-[12]\d\d\d/, ""
467
+ me.id&.sub!(/-[12]\d\d\d/, "")
464
468
  me
465
469
  end
466
470
 
@@ -477,7 +481,7 @@ module RelatonBib
477
481
  # @param prefix [String]
478
482
  # @return [String]
479
483
  def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
480
- pref = prefix.empty? ? prefix : prefix + "."
484
+ pref = prefix.empty? ? prefix : "#{prefix}."
481
485
  out = prefix.empty? ? "[%bibitem]\n== {blank}\n" : ""
482
486
  out += "#{pref}id:: #{id}\n" if id
483
487
  out += "#{pref}fetched:: #{fetched}\n" if fetched
@@ -513,6 +517,7 @@ module RelatonBib
513
517
  out += relation.to_asciibib prefix if relation
514
518
  series.each { |s| out += s.to_asciibib prefix, series.size }
515
519
  out += "#{pref}doctype:: #{doctype}\n" if doctype
520
+ out += "#{pref}subdoctype:: #{subdoctype}\n" if subdoctype
516
521
  out += "#{pref}formattedref:: #{formattedref}\n" if formattedref
517
522
  keyword.each { |kw| out += kw.to_asciibib "#{pref}keyword", keyword.size }
518
523
  out += editorialgroup.to_asciibib prefix if editorialgroup
@@ -682,21 +687,21 @@ module RelatonBib
682
687
  root = opts[:bibdata] ? :bibdata : :bibitem
683
688
  xml = opts[:builder].send(root) do |builder|
684
689
  builder.fetched fetched if fetched
685
- title.to_xml **opts
690
+ title.to_xml(**opts)
686
691
  formattedref&.to_xml builder
687
692
  link.each { |s| s.to_xml builder }
688
- docidentifier.each { |di| di.to_xml **opts }
693
+ docidentifier.each { |di| di.to_xml(**opts) }
689
694
  builder.docnumber docnumber if docnumber
690
695
  date.each { |d| d.to_xml builder, **opts }
691
696
  contributor.each do |c|
692
697
  builder.contributor do
693
- c.role.each { |r| r.to_xml **opts }
694
- c.to_xml **opts
698
+ c.role.each { |r| r.to_xml(**opts) }
699
+ c.to_xml(**opts)
695
700
  end
696
701
  end
697
702
  builder.edition edition if edition
698
703
  version&.to_xml builder
699
- biblionote.to_xml **opts
704
+ biblionote.to_xml(**opts)
700
705
  opts[:note]&.each do |n|
701
706
  builder.note(n[:text], format: "text/plain", type: n[:type])
702
707
  end
@@ -706,7 +711,7 @@ module RelatonBib
706
711
  abstr = abstract unless abstr.any?
707
712
  abstr.each { |a| builder.abstract { a.to_xml(builder) } }
708
713
  status&.to_xml builder
709
- copyright&.each { |c| c.to_xml **opts }
714
+ copyright&.each { |c| c.to_xml(**opts) }
710
715
  relation.each { |r| r.to_xml builder, **opts }
711
716
  series.each { |s| s.to_xml builder }
712
717
  medium&.to_xml builder
@@ -724,6 +729,7 @@ module RelatonBib
724
729
  structuredidentifier&.presence?)
725
730
  builder.ext do |b|
726
731
  b.doctype doctype if doctype
732
+ b.subdoctype subdoctype if subdoctype
727
733
  editorialgroup&.to_xml b
728
734
  ics.each { |i| i.to_xml b }
729
735
  structuredidentifier&.to_xml b
@@ -13,7 +13,7 @@ module RelatonBib
13
13
  derives describes describedBy catalogues cataloguedBy hasSuccessor
14
14
  successorOf adaptedFrom hasAdaptation adoptedFrom adoptedAs reviewOf
15
15
  hasReview commentaryOf hasCommentary related complements complementOf
16
- obsoletes obsoletedBy cited isCitedIn
16
+ obsoletes obsoletedBy cites isCitedIn
17
17
  ].freeze
18
18
 
19
19
  # @return [String]
@@ -42,7 +42,7 @@ module RelatonBib
42
42
  # @param prefix [String]
43
43
  # @return [String]
44
44
  def to_asciibib(prefix = "")
45
- pref = prefix.empty? ? prefix : prefix + "."
45
+ pref = prefix.empty? ? prefix : "#{prefix}."
46
46
  out = "#{pref}docstatus.stage:: #{stage.value}\n"
47
47
  out += "#{pref}docstatus.substage:: #{substage.value}\n" if substage
48
48
  out += "#{pref}docstatus.iteration:: #{iteration}\n" if iteration
@@ -54,9 +54,10 @@ module RelatonBib
54
54
  # @param stg [RelatonBib::DocumentStatus::Stage, Hash, String, NilClass]
55
55
  # @return [RelatonBib::DocumentStatus::Stage]
56
56
  def stage_new(stg)
57
- if stg.is_a?(Stage) then stg
58
- elsif stg.is_a?(Hash) then Stage.new(**stg)
59
- elsif stg.is_a?(String) then Stage.new(value: stg)
57
+ case stg
58
+ when Stage then stg
59
+ when Hash then Stage.new(**stg)
60
+ when String then Stage.new(value: stg)
60
61
  end
61
62
  end
62
63
 
@@ -27,7 +27,7 @@ module RelatonBib
27
27
  # @param prefix [String]
28
28
  # @return [String]
29
29
  def to_asciibib(prefix = "")
30
- pref = prefix.empty? ? "editorialgroup" : prefix + ".editorialgroup"
30
+ pref = prefix.empty? ? "editorialgroup" : "#{prefix}.editorialgroup"
31
31
  technical_committee.map do |tc|
32
32
  tc.to_asciibib pref, technical_committee.size
33
33
  end.join
@@ -10,7 +10,7 @@ module RelatonBib
10
10
  # @param prefix [String]
11
11
  # @return [String]
12
12
  def to_asciibib(prefix = "")
13
- pref = prefix.empty? ? "formattedref" : prefix + ".formattedref"
13
+ pref = prefix.empty? ? "formattedref" : "#{prefix}.formattedref"
14
14
  super pref
15
15
  end
16
16
  end
@@ -7,7 +7,7 @@ module RelatonBib
7
7
  class FormattedString < LocalizedString
8
8
  FORMATS = %w[text/plain text/html application/docbook+xml
9
9
  application/tei+xml text/x-asciidoc text/markdown
10
- application/x-isodoc+xml].freeze
10
+ application/x-metanorma+xml].freeze
11
11
 
12
12
  # @return [String]
13
13
  attr_reader :format
@@ -107,7 +107,7 @@ module RelatonBib
107
107
  ret[:accesslocation] = array(ret[:accesslocation])
108
108
  end
109
109
 
110
- def dates_hash_to_bib(ret)
110
+ def dates_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
111
111
  return unless ret[:date]
112
112
 
113
113
  ret[:date] = array(ret[:date])
@@ -160,7 +160,7 @@ module RelatonBib
160
160
  ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
161
161
  stage: stage(ret[:docstatus][:stage]),
162
162
  substage: stage(ret[:docstatus][:substage]),
163
- iteration: ret[:docstatus][:iteration]
163
+ iteration: ret[:docstatus][:iteration],
164
164
  )
165
165
  end
166
166
 
@@ -215,7 +215,7 @@ module RelatonBib
215
215
  name: fullname_hash_to_bib(person),
216
216
  affiliation: affiliation_hash_to_bib(person),
217
217
  contact: contacts_hash_to_bib(person),
218
- identifier: person_identifiers_hash_to_bib(person)
218
+ identifier: person_identifiers_hash_to_bib(person),
219
219
  )
220
220
  end
221
221
 
@@ -227,7 +227,7 @@ module RelatonBib
227
227
  addition: array(n[:addition])&.map { |f| localname(f, person) },
228
228
  prefix: array(n[:prefix])&.map { |f| localname(f, person) },
229
229
  surname: localname(n[:surname], person),
230
- completename: localname(n[:completename], person)
230
+ completename: localname(n[:completename], person),
231
231
  )
232
232
  end
233
233
 
@@ -247,11 +247,11 @@ module RelatonBib
247
247
  script: d[:script], format: d[:format] }
248
248
  else { content: d }
249
249
  end
250
- FormattedString.new **cnt
250
+ FormattedString.new(**cnt)
251
251
  end
252
252
  Affiliation.new(
253
253
  organization: Organization.new(**org_hash_to_bib(a[:organization])),
254
- description: a[:description]
254
+ description: a[:description],
255
255
  )
256
256
  end
257
257
  end
@@ -288,7 +288,7 @@ module RelatonBib
288
288
  ret[:relation] = array(ret[:relation])
289
289
  ret[:relation]&.each do |r|
290
290
  if r[:description]
291
- r[:description] = FormattedString.new **r[:description]
291
+ r[:description] = FormattedString.new(**r[:description])
292
292
  end
293
293
  relation_bibitem_hash_to_bib(r)
294
294
  relation_locality_hash_to_bib(r)
@@ -309,7 +309,7 @@ module RelatonBib
309
309
  # @param item_hash [Hash]
310
310
  # @return [RelatonBib::BibliographicItem]
311
311
  def bib_item(item_hash)
312
- BibliographicItem.new **item_hash
312
+ BibliographicItem.new(**item_hash)
313
313
  end
314
314
 
315
315
  # @param rel [Hash] relation
@@ -363,7 +363,7 @@ module RelatonBib
363
363
  # @param title [Hash]
364
364
  # @return [RelatonBib::TypedTitleString]
365
365
  def typed_title_strig(title)
366
- TypedTitleString.new **title
366
+ TypedTitleString.new(**title)
367
367
  end
368
368
 
369
369
  # @param ret [Hash]
@@ -375,7 +375,7 @@ module RelatonBib
375
375
  def classification_hash_to_bib(ret)
376
376
  if ret[:classification]
377
377
  ret[:classification] = array(ret[:classification]).map do |cls|
378
- Classification.new **cls
378
+ Classification.new(**cls)
379
379
  end
380
380
  end
381
381
  end
@@ -418,7 +418,7 @@ module RelatonBib
418
418
  def ics_hash_to_bib(ret)
419
419
  return unless ret[:ics]
420
420
 
421
- ret[:ics] = array(ret[:ics]).map { |ics| ICS.new **ics }
421
+ ret[:ics] = array(ret[:ics]).map { |ics| ICS.new(**ics) }
422
422
  end
423
423
 
424
424
  # @param ret [Hash]
@@ -427,7 +427,7 @@ module RelatonBib
427
427
 
428
428
  sids = array(ret[:structuredidentifier]).map do |si|
429
429
  si[:agency] = array si[:agency]
430
- StructuredIdentifier.new **si
430
+ StructuredIdentifier.new(**si)
431
431
  end
432
432
  ret[:structuredidentifier] = StructuredIdentifierCollection.new sids
433
433
  end
@@ -435,15 +435,14 @@ module RelatonBib
435
435
  # @param ogj [Hash, Array, String]
436
436
  # @return [Hash, Array, String]
437
437
  def symbolize(obj)
438
- if obj.is_a? Hash
438
+ case obj
439
+ when Hash
439
440
  obj.reduce({}) do |memo, (k, v)|
440
441
  memo[k.to_sym] = symbolize(v)
441
442
  memo
442
443
  end
443
- elsif obj.is_a? Array
444
- obj.reduce([]) { |memo, v| memo << symbolize(v) }
445
- else
446
- obj
444
+ when Array then obj.reduce([]) { |memo, v| memo << symbolize(v) }
445
+ else obj
447
446
  end
448
447
  end
449
448
 
@@ -459,7 +458,7 @@ module RelatonBib
459
458
  # @param name [Hash, String, NilClass]
460
459
  # @param person [Hash]
461
460
  # @return [RelatonBib::LocalizedString]
462
- def localname(name, person) # rubocop:disable Metrics/CyclomaticComplexity
461
+ def localname(name, person) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize
463
462
  return nil if name.nil?
464
463
 
465
464
  lang = name[:language] if name.is_a?(Hash)
@@ -21,10 +21,10 @@ module RelatonBib
21
21
  # @return [String]
22
22
  def inspect
23
23
  "<#{self.class}:#{format('%<id>#.14x', id: object_id << 1)} "\
24
- "@text=\"#{@hit_collection&.text}\" "\
25
- "@fetched=\"#{!@fetch.nil?}\" "\
26
- "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
27
- "@title=\"#{@hit[:code]}\">"
24
+ "@text=\"#{@hit_collection&.text}\" "\
25
+ "@fetched=\"#{!@fetch.nil?}\" "\
26
+ "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
27
+ "@title=\"#{@hit[:code]}\">"
28
28
  end
29
29
 
30
30
  def fetch
@@ -38,10 +38,10 @@ module RelatonBib
38
38
  # @return [String] XML
39
39
  def to_xml(**opts)
40
40
  if opts[:builder]
41
- fetch.to_xml **opts
41
+ fetch.to_xml(**opts)
42
42
  else
43
43
  builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
44
- fetch.to_xml **opts.merge(builder: xml)
44
+ fetch.to_xml(**opts.merge(builder: xml))
45
45
  end
46
46
  builder.doc.root.to_xml
47
47
  end