relaton-bib 1.11.6 → 1.12.1

Sign up to get free protection for your applications and to get access to all the features.
data/grammars/isodoc.rng CHANGED
@@ -32,6 +32,43 @@
32
32
  <ref name="DocumentType"/>
33
33
  </element>
34
34
  </define>
35
+ <define name="admonition">
36
+ <element name="admonition">
37
+ <attribute name="type">
38
+ <ref name="AdmonitionType"/>
39
+ </attribute>
40
+ <optional>
41
+ <attribute name="class"/>
42
+ </optional>
43
+ <attribute name="id">
44
+ <data type="ID"/>
45
+ </attribute>
46
+ <optional>
47
+ <attribute name="uri">
48
+ <data type="anyURI"/>
49
+ </attribute>
50
+ </optional>
51
+ <optional>
52
+ <attribute name="coverpage">
53
+ <data type="boolean"/>
54
+ </attribute>
55
+ </optional>
56
+ <optional>
57
+ <attribute name="notag">
58
+ <data type="boolean"/>
59
+ </attribute>
60
+ </optional>
61
+ <optional>
62
+ <ref name="tname"/>
63
+ </optional>
64
+ <zeroOrMore>
65
+ <ref name="paragraph-with-footnote"/>
66
+ </zeroOrMore>
67
+ <zeroOrMore>
68
+ <ref name="note"/>
69
+ </zeroOrMore>
70
+ </element>
71
+ </define>
35
72
  <define name="index">
36
73
  <element name="index">
37
74
  <optional>
@@ -79,6 +116,11 @@
79
116
  <data type="boolean"/>
80
117
  </attribute>
81
118
  </optional>
119
+ <optional>
120
+ <attribute name="suppress_identifier">
121
+ <data type="boolean"/>
122
+ </attribute>
123
+ </optional>
82
124
  <ref name="BibliographicItem"/>
83
125
  </element>
84
126
  </define>
@@ -245,6 +287,9 @@
245
287
  <ref name="MultilingualRenderingType"/>
246
288
  </attribute>
247
289
  </optional>
290
+ <optional>
291
+ <ref name="tname"/>
292
+ </optional>
248
293
  <oneOrMore>
249
294
  <ref name="ul_li"/>
250
295
  </oneOrMore>
@@ -287,6 +332,9 @@
287
332
  </choice>
288
333
  </attribute>
289
334
  </optional>
335
+ <optional>
336
+ <ref name="tname"/>
337
+ </optional>
290
338
  <oneOrMore>
291
339
  <ref name="li"/>
292
340
  </oneOrMore>
@@ -323,6 +371,9 @@
323
371
  <ref name="MultilingualRenderingType"/>
324
372
  </attribute>
325
373
  </optional>
374
+ <optional>
375
+ <ref name="tname"/>
376
+ </optional>
326
377
  <oneOrMore>
327
378
  <ref name="dt"/>
328
379
  <ref name="dd"/>
@@ -657,6 +708,9 @@
657
708
  <optional>
658
709
  <attribute name="tag"/>
659
710
  </optional>
711
+ <optional>
712
+ <attribute name="type"/>
713
+ </optional>
660
714
  <optional>
661
715
  <attribute name="multilingual-rendering">
662
716
  <ref name="MultilingualRenderingType"/>
@@ -692,6 +746,9 @@
692
746
  <optional>
693
747
  <attribute name="tag"/>
694
748
  </optional>
749
+ <optional>
750
+ <attribute name="type"/>
751
+ </optional>
695
752
  <optional>
696
753
  <attribute name="multilingual-rendering">
697
754
  <ref name="MultilingualRenderingType"/>
@@ -851,6 +908,16 @@
851
908
  <ref name="MultilingualRenderingType"/>
852
909
  </attribute>
853
910
  </optional>
911
+ <optional>
912
+ <attribute name="coverpage">
913
+ <data type="boolean"/>
914
+ </attribute>
915
+ </optional>
916
+ <optional>
917
+ <attribute name="notag">
918
+ <data type="boolean"/>
919
+ </attribute>
920
+ </optional>
854
921
  <oneOrMore>
855
922
  <choice>
856
923
  <ref name="paragraph"/>
@@ -1178,6 +1245,7 @@
1178
1245
  <ref name="concept"/>
1179
1246
  <ref name="add"/>
1180
1247
  <ref name="del"/>
1248
+ <ref name="span"/>
1181
1249
  </choice>
1182
1250
  </define>
1183
1251
  <define name="add">
@@ -1204,6 +1272,14 @@
1204
1272
  </choice>
1205
1273
  </element>
1206
1274
  </define>
1275
+ <define name="span">
1276
+ <element name="span">
1277
+ <attribute name="class"/>
1278
+ <oneOrMore>
1279
+ <ref name="TextElement"/>
1280
+ </oneOrMore>
1281
+ </element>
1282
+ </define>
1207
1283
  <define name="concept">
1208
1284
  <element name="concept">
1209
1285
  <optional>
@@ -1994,6 +2070,7 @@
1994
2070
  <value>compare</value>
1995
2071
  <value>contrast</value>
1996
2072
  <value>see</value>
2073
+ <value>seealso</value>
1997
2074
  </choice>
1998
2075
  </define>
1999
2076
  <define name="deprecates">
@@ -17,7 +17,7 @@ module RelatonBib
17
17
  type_ptrn = %r{section|clause|part|paragraph|chapter|page|whole|table|
18
18
  annex|figure|note|list|example|volume|issue|time|
19
19
  locality:[a-zA-Z0-9_]+}x
20
- unless type.match? type_ptrn
20
+ unless type&.match? type_ptrn
21
21
  warn "[relaton-bib] WARNING: invalid locality type: #{type}"
22
22
  end
23
23
 
@@ -4,15 +4,12 @@ module RelatonBib
4
4
  class Version
5
5
  include RelatonBib
6
6
 
7
- # @return [String, NilClass]
8
- attr_reader :revision_date
7
+ # @return [String, nil]
8
+ attr_reader :revision_date, :draft
9
9
 
10
- # @return [Array<String>]
11
- attr_reader :draft
12
-
13
- # @param revision_date [String, NilClass]
14
- # @param draft [Array<String>]
15
- def initialize(revision_date = nil, draft = [])
10
+ # @param revision_date [String, nil]
11
+ # @param draft [String, nil]
12
+ def initialize(revision_date = nil, draft = nil)
16
13
  @revision_date = revision_date
17
14
  @draft = draft
18
15
  end
@@ -20,8 +17,8 @@ module RelatonBib
20
17
  # @param builder [Nokogiri::XML::Builder]
21
18
  def to_xml(builder)
22
19
  builder.version do
23
- builder.send("revision-date", revision_date) if revision_date
24
- draft.each { |d| builder.draft d }
20
+ builder.send(:"revision-date", revision_date) if revision_date
21
+ builder.draft draft if draft
25
22
  end
26
23
  end
27
24
 
@@ -29,19 +26,19 @@ module RelatonBib
29
26
  def to_hash
30
27
  hash = {}
31
28
  hash["revision_date"] = revision_date if revision_date
32
- hash["draft"] = single_element_array(draft) if draft&.any?
29
+ hash["draft"] = draft if draft
33
30
  hash
34
31
  end
35
32
 
36
33
  # @param prefix [String]
37
34
  # @return [String]
38
- def to_asciibib(prefix = "")
39
- pref = prefix.empty? ? prefix : prefix + "."
40
- out = ""
35
+ def to_asciibib(prefix = "", count = 1)
36
+ pref = prefix.empty? ? prefix : "#{prefix}."
37
+ out = count > 1 ? "#{prefix}version::\n" : ""
41
38
  if revision_date
42
39
  out += "#{pref}version.revision_date:: #{revision_date}\n"
43
40
  end
44
- draft&.each { |d| out += "#{pref}version.draft:: #{d}\n" }
41
+ out += "#{pref}version.draft:: #{draft}\n" if draft
45
42
  out
46
43
  end
47
44
  end
@@ -41,7 +41,8 @@ module RelatonBib
41
41
  when :year then parts[0]&.to_i
42
42
  when :month then parts[1]&.to_i
43
43
  when :day then parts[2]&.to_i
44
- else parse_date(d)
44
+ when :date then parse_date(d)
45
+ else d
45
46
  end
46
47
 
47
48
  # date.is_a?(Date) ? date.send(part) : date
@@ -28,6 +28,7 @@ require "relaton_bib/structured_identifier"
28
28
  require "relaton_bib/editorial_group"
29
29
  require "relaton_bib/ics"
30
30
  require "relaton_bib/bibliographic_size"
31
+ require "relaton_bib/edition"
31
32
 
32
33
  module RelatonBib
33
34
  # Bibliographic item
@@ -37,13 +38,18 @@ module RelatonBib
37
38
  TYPES = %W[article book booklet conference manual proceedings presentation
38
39
  thesis techreport standard unpublished map electronic\sresource
39
40
  audiovisual film video broadcast graphic_work music patent
40
- inbook incollection inproceedings journal].freeze
41
+ inbook incollection inproceedings journal software website
42
+ webresource dataset archival social_media alert message
43
+ conversation misc].freeze
41
44
 
42
- # @return [TrueClass, FalseClass, NilClass]
45
+ # @return [Boolean, nil]
43
46
  attr_accessor :all_parts
44
47
 
45
- # @return [String, NilClass]
46
- attr_reader :id, :type, :docnumber, :edition, :doctype, :subdoctype
48
+ # @return [String, nil]
49
+ attr_reader :id, :type, :docnumber, :doctype, :subdoctype
50
+
51
+ # @return [RelatonBib::Edition, nil] <description>
52
+ attr_reader :edition
47
53
 
48
54
  # @!attribute [r] title
49
55
  # @return [RelatonBib::TypedTitleStringCollection]
@@ -60,7 +66,7 @@ module RelatonBib
60
66
  # @return [Array<RelatonBib::ContributionInfo>]
61
67
  attr_reader :contributor
62
68
 
63
- # @return [RelatonBib::BibliographicItem::Version, NilClass]
69
+ # @return [Array<RelatonBib::BibliographicItem::Version>]
64
70
  attr_reader :version
65
71
 
66
72
  # @return [RelatonBib::BiblioNoteCollection]
@@ -72,13 +78,13 @@ module RelatonBib
72
78
  # @return [Array<String>] script Iso15924 code
73
79
  attr_reader :script
74
80
 
75
- # @return [RelatonBib::FormattedRef, NilClass]
81
+ # @return [RelatonBib::FormattedRef, nil]
76
82
  attr_reader :formattedref
77
83
 
78
84
  # @!attribute [r] abstract
79
85
  # @return [Array<RelatonBib::FormattedString>]
80
86
 
81
- # @return [RelatonBib::DocumentStatus, NilClass]
87
+ # @return [RelatonBib::DocumentStatus, nil]
82
88
  attr_reader :status
83
89
 
84
90
  # @return [Array<RelatonBib::CopyrightAssociation>]
@@ -90,7 +96,7 @@ module RelatonBib
90
96
  # @return [Array<RelatonBib::Series>]
91
97
  attr_reader :series
92
98
 
93
- # @return [RelatonBib::Medium, NilClass]
99
+ # @return [RelatonBib::Medium, nil]
94
100
  attr_reader :medium
95
101
 
96
102
  # @return [Array<RelatonBib::Place>]
@@ -105,7 +111,7 @@ module RelatonBib
105
111
  # @return [Array<Relaton::Classification>]
106
112
  attr_reader :classification
107
113
 
108
- # @return [RelatonBib:Validity, NilClass]
114
+ # @return [RelatonBib:Validity, nil]
109
115
  attr_reader :validity
110
116
 
111
117
  # @return [Date]
@@ -129,18 +135,18 @@ module RelatonBib
129
135
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
130
136
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
131
137
 
132
- # @param id [String, NilClass]
138
+ # @param id [String, nil]
133
139
  # @param title [RelatonBib::TypedTitleStringCollection,
134
140
  # Array<Hash, RelatonBib::TypedTitleString>]
135
- # @param formattedref [RelatonBib::FormattedRef, NilClass]
136
- # @param type [String, NilClass]
141
+ # @param formattedref [RelatonBib::FormattedRef, nil]
142
+ # @param type [String, nil]
137
143
  # @param docid [Array<RelatonBib::DocumentIdentifier>]
138
- # @param docnumber [String, NilClass]
144
+ # @param docnumber [String, nil]
139
145
  # @param language [Arra<String>]
140
146
  # @param script [Array<String>]
141
- # @param docstatus [RelatonBib::DocumentStatus, NilClass]
142
- # @param edition [String, NilClass]
143
- # @param version [RelatonBib::BibliographicItem::Version, NilClass]
147
+ # @param docstatus [RelatonBib::DocumentStatus, nil]
148
+ # @param edition [RelatonBib::Edition, nil]
149
+ # @param version [Array<RelatonBib::BibliographicItem::Version>]
144
150
  # @param biblionote [RelatonBib::BiblioNoteCollection]
145
151
  # @param series [Array<RelatonBib::Series>]
146
152
  # @param medium [RelatonBib::Medium, NilClas]
@@ -148,8 +154,8 @@ module RelatonBib
148
154
  # @param extent [Array<Relaton::Locality, RelatonBib::LocalityStack>]
149
155
  # @param accesslocation [Array<String>]
150
156
  # @param classification [Array<RelatonBib::Classification>]
151
- # @param validity [RelatonBib:Validity, NilClass]
152
- # @param fetched [Date, NilClass] default nil
157
+ # @param validity [RelatonBib:Validity, nil]
158
+ # @param fetched [Date, nil] default nil
153
159
  # @param keyword [Array<String>]
154
160
  # @param doctype [String]
155
161
  # @param subdoctype [String]
@@ -161,8 +167,8 @@ module RelatonBib
161
167
  # @param copyright [Array<Hash, RelatonBib::CopyrightAssociation>]
162
168
  # @option copyright [Array<Hash, RelatonBib::ContributionInfo>] :owner
163
169
  # @option copyright [String] :from
164
- # @option copyright [String, NilClass] :to
165
- # @option copyright [String, NilClass] :scope
170
+ # @option copyright [String, nil] :to
171
+ # @option copyright [String, nil] :scope
166
172
  #
167
173
  # @param date [Array<Hash, RelatonBib::BibliographicDate>]
168
174
  # @option date [String] :type
@@ -228,8 +234,12 @@ module RelatonBib
228
234
  @id = args[:id] || makeid(nil, false)
229
235
  @type = args[:type]
230
236
  @docnumber = args[:docnumber]
231
- @edition = args[:edition]
232
- @version = args[:version]
237
+ @edition = case args[:edition]
238
+ when Hash then Edition.new(**args[:edition])
239
+ when String then Edition.new(content: args[:edition])
240
+ else args[:edition]
241
+ end
242
+ @version = args.fetch :version, []
233
243
  @biblionote = args.fetch :biblionote, BiblioNoteCollection.new([])
234
244
  @language = args.fetch :language, []
235
245
  @script = args.fetch :script, []
@@ -319,7 +329,7 @@ module RelatonBib
319
329
  # @param opts [Hash]
320
330
  # @option opts [Nokogiri::XML::Builder] :builder XML builder
321
331
  # @option opts [Boolean] :bibdata
322
- # @option opts [Symbol, NilClass] :date_format (:short), :full
332
+ # @option opts [Symbol, nil] :date_format (:short), :full
323
333
  # @option opts [String, Symbol] :lang language
324
334
  # @return [String] XML
325
335
  def to_xml(**opts, &block)
@@ -363,8 +373,8 @@ module RelatonBib
363
373
  if contributor&.any?
364
374
  hash["contributor"] = single_element_array(contributor)
365
375
  end
366
- hash["edition"] = edition if edition
367
- hash["version"] = version.to_hash if version
376
+ hash["edition"] = edition.to_hash if edition
377
+ hash["version"] = version.map &:to_hash if version.any?
368
378
  hash["revdate"] = revdate if revdate
369
379
  hash["biblionote"] = single_element_array(biblionote) if biblionote&.any?
370
380
  hash["language"] = single_element_array(language) if language&.any?
@@ -491,10 +501,10 @@ module RelatonBib
491
501
  end
492
502
 
493
503
  # If revision_date exists then returns it else returns published date or nil
494
- # @return [String, NilClass]
504
+ # @return [String, nil]
495
505
  def revdate # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
496
- @revdate ||= if version&.revision_date
497
- version.revision_date
506
+ @revdate ||= if (v = version.detect &:revision_date)
507
+ v.revision_date
498
508
  else
499
509
  date.detect { |d| d.type == "published" }&.on&.to_s
500
510
  end
@@ -513,10 +523,10 @@ module RelatonBib
513
523
  out += di.to_asciibib prefix, docidentifier.size
514
524
  end
515
525
  out += "#{pref}docnumber:: #{docnumber}\n" if docnumber
516
- out += "#{pref}edition:: #{edition}\n" if edition
526
+ out += edition.to_asciibib(prefix) if edition
517
527
  language.each { |l| out += "#{pref}language:: #{l}\n" }
518
528
  script.each { |s| out += "#{pref}script:: #{s}\n" }
519
- out += version.to_asciibib prefix if version
529
+ version.each { |v| out += v.to_asciibib prefix, version.size }
520
530
  biblionote&.each { |b| out += b.to_asciibib prefix, biblionote.size }
521
531
  out += status.to_asciibib prefix if status
522
532
  date.each { |d| out += d.to_asciibib prefix, date.size }
@@ -563,7 +573,7 @@ module RelatonBib
563
573
  item.type = bibtex_type
564
574
  item.key = id
565
575
  title.to_bibtex item
566
- item.edition = edition if edition
576
+ item.edition = edition.content if edition
567
577
  bibtex_author item
568
578
  bibtex_contributor item
569
579
  item.address = place.first.name if place.any?
@@ -717,7 +727,7 @@ module RelatonBib
717
727
  # @param opts [Hash]
718
728
  # @option opts [Nokogiri::XML::Builder] :builder XML builder
719
729
  # @option opts [Boolean] bibdata
720
- # @option opts [Symbol, NilClass] :date_format (:short), :full
730
+ # @option opts [Symbol, nil] :date_format (:short), :full
721
731
  # @option opts [String] :lang language
722
732
  def render_xml(**opts)
723
733
  root = opts[:bibdata] ? :bibdata : :bibitem
@@ -735,8 +745,8 @@ module RelatonBib
735
745
  c.to_xml(**opts)
736
746
  end
737
747
  end
738
- builder.edition edition if edition
739
- version&.to_xml builder
748
+ edition&.to_xml builder
749
+ version.each { |v| v.to_xml builder }
740
750
  biblionote.to_xml(**opts)
741
751
  opts[:note]&.each do |n|
742
752
  builder.note(n[:text], format: "text/plain", type: n[:type])
@@ -788,7 +798,8 @@ module RelatonBib
788
798
  def render_bibxml(builder, include_keywords)
789
799
  target = link.detect { |l| l.type.casecmp("src").zero? } ||
790
800
  link.detect { |l| l.type.casecmp("doi").zero? }
791
- bxml = if docnumber&.match(/^BCP/) || docidentifier[0].id.include?("BCP")
801
+ bxml = if docnumber&.match(/^BCP/) || (docidentifier.detect(&:primary)&.id ||
802
+ docidentifier[0].id).include?("BCP")
792
803
  render_bibxml_refgroup(builder, include_keywords)
793
804
  else
794
805
  render_bibxml_ref(builder, include_keywords)
@@ -818,13 +829,17 @@ module RelatonBib
818
829
  #
819
830
  def render_bibxml_ref(builder, include_keywords)
820
831
  builder.reference(**ref_attrs) do |xml|
821
- xml.front do
822
- xml.title title[0].title.content if title.any?
823
- render_authors xml
824
- render_date xml
825
- render_workgroup xml
826
- render_keyword xml if include_keywords
827
- render_abstract xml
832
+ if title.any? || contributor.any? || date.any? || abstract.any? ||
833
+ editorialgroup&.technical_committee&.any? ||
834
+ (include_keywords && keyword.any?)
835
+ xml.front do
836
+ xml.title title[0].title.content if title.any?
837
+ render_authors xml
838
+ render_date xml
839
+ render_workgroup xml
840
+ render_keyword xml if include_keywords
841
+ render_abstract xml
842
+ end
828
843
  end
829
844
  render_seriesinfo xml
830
845
  render_format xml
@@ -7,11 +7,21 @@ module RelatonBib
7
7
  FLAVOR = nil
8
8
 
9
9
  ORGNAMES = {
10
- "IEEE" => "Istitute of Electrical and Electronics Engineers",
10
+ "IEEE" => "Institute of Electrical and Electronics Engineers",
11
11
  "W3C" => "World Wide Web Consortium",
12
12
  "3GPP" => "3rd Generation Partnership Project",
13
13
  }.freeze
14
14
 
15
+ #
16
+ # Parse BibXML content
17
+ #
18
+ # @param [String] bibxml content
19
+ # @param [String, nil] url source URL
20
+ # @param [Boolean] is_relation true if the content is relation item
21
+ # @param [String, nil] ver version
22
+ #
23
+ # @return [<Type>] <description>
24
+ #
15
25
  def parse(bibxml, url: nil, is_relation: false, ver: nil)
16
26
  doc = Nokogiri::XML bibxml
17
27
  fetch_rfc doc.at("/referencegroup", "/reference"), url: url, is_relation: is_relation, ver: ver
@@ -4,21 +4,24 @@ module RelatonBib
4
4
  # @return [String]
5
5
  attr_reader :id
6
6
 
7
- # @return [String, NilClass]
8
- attr_reader :type, :scope
7
+ # @return [String, nil]
8
+ attr_reader :type, :scope, :language, :script
9
9
 
10
10
  # @param type [Boolean, nil]
11
11
  attr_reader :primary
12
12
 
13
13
  # @param id [String]
14
- # @param type [String, NilClass]
15
- # @param scope [String, NilClass]
16
- # @param priority [Bolean]
17
- def initialize(id:, type: nil, scope: nil, primary: false)
18
- @id = id
19
- @type = type
20
- @scope = scope
21
- @primary = primary
14
+ # @param type [String, nil]
15
+ # @param scope [String, nil]
16
+ # @param primary [Bolean, nil]
17
+ # @param language [String, nil]
18
+ def initialize(**args)
19
+ @id = args[:id]
20
+ @type = args[:type]
21
+ @scope = args[:scope]
22
+ @primary = args[:primary]
23
+ @language = args[:language]
24
+ @script = args[:script]
22
25
  end
23
26
 
24
27
  # in docid manipulations, assume ISO as the default: id-part:year
@@ -53,7 +56,7 @@ module RelatonBib
53
56
  # @param opts [Hash]
54
57
  # @option opts [Nokogiri::XML::Builder] :builder XML builder
55
58
  # @option opts [String] :lang language
56
- def to_xml(**opts) # rubocop:disable Metrics/AbcSize
59
+ def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
57
60
  lid = if type == "URN" && opts[:lang]
58
61
  id.sub %r{(?<=:)(?:\w{2},)*?(#{opts[:lang]})(?:,\w{2})*}, '\1'
59
62
  else id
@@ -62,14 +65,18 @@ module RelatonBib
62
65
  element[:type] = type if type
63
66
  element[:scope] = scope if scope
64
67
  element[:primary] = primary if primary
68
+ element[:language] = language if language
69
+ element[:script] = script if script
65
70
  end
66
71
 
67
72
  # @return [Hash]
68
- def to_hash
73
+ def to_hash # rubocop:disable Metrics/AbcSize
69
74
  hash = { "id" => id }
70
75
  hash["type"] = type if type
71
76
  hash["scope"] = scope if scope
72
77
  hash["primary"] = primary if primary
78
+ hash["language"] = language if language
79
+ hash["script"] = script if script
73
80
  hash
74
81
  end
75
82
 
@@ -84,6 +91,8 @@ module RelatonBib
84
91
  out += "#{pref}docid.type:: #{type}\n" if type
85
92
  out += "#{pref}docid.scope:: #{scope}\n" if scope
86
93
  out += "#{pref}docid.primary:: #{primary}\n" if primary
94
+ out += "#{pref}docid.language:: #{language}\n" if language
95
+ out += "#{pref}docid.script:: #{script}\n" if script
87
96
  out + "#{pref}docid.id:: #{id}\n"
88
97
  end
89
98
 
@@ -0,0 +1,55 @@
1
+ module RelatonBib
2
+ class Edition
3
+ # @return [String] edition
4
+ attr_reader :content
5
+
6
+ # @return [String, nil] number
7
+ attr_reader :number
8
+
9
+ #
10
+ # Initialize edition.
11
+ #
12
+ # @param [String] content edition
13
+ # @param [String, nil] number number
14
+ #
15
+ def initialize(content:, number: nil)
16
+ @content = content
17
+ @number = number
18
+ end
19
+
20
+ #
21
+ # Render edition as XML.
22
+ #
23
+ # @param [Nokogiri::XML::Builder] builder XML builder
24
+ #
25
+ def to_xml(builder)
26
+ node = builder.edition(content)
27
+ node[:number] = number if number
28
+ end
29
+
30
+ #
31
+ # Return edition as hash.
32
+ #
33
+ # @return [Hash] edition as hash.
34
+ #
35
+ def to_hash
36
+ hash = { "content" => content }
37
+ hash["number"] = number if number
38
+ hash
39
+ end
40
+
41
+ #
42
+ # Render edition as AsciiBib.
43
+ #
44
+ # @param [String] prefix prefix
45
+ #
46
+ # @return [String] edition as AsciiBib.
47
+ #
48
+ def to_asciibib(prefix = "")
49
+ pref = prefix.empty? ? "edition" : "#{prefix}.edition"
50
+ out = "#{pref}.content:: #{content}\n"
51
+ out += "#{pref}.number:: #{number}\n" if number
52
+ out
53
+ end
54
+ end
55
+ end