relaton-bib 1.20.7 → 2.0.0.pre.alpha.1

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.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/README.adoc +183 -154
  4. data/bin/console +1 -1
  5. data/grammars/basicdoc.rng +1516 -645
  6. data/grammars/biblio-standoc.rng +100 -20
  7. data/grammars/biblio.rng +959 -356
  8. data/grammars/versions.json +10 -10
  9. data/lib/relaton/bib/hash_parser_v1.rb +711 -0
  10. data/lib/relaton/bib/item_data.rb +168 -0
  11. data/lib/relaton/bib/model/address.rb +22 -0
  12. data/lib/relaton/bib/model/affiliation.rb +16 -0
  13. data/lib/relaton/bib/model/bibdata.rb +24 -0
  14. data/lib/relaton/bib/model/bibitem.rb +23 -0
  15. data/lib/relaton/bib/model/contact.rb +18 -0
  16. data/lib/relaton/bib/model/contribution_info.rb +16 -0
  17. data/lib/relaton/bib/model/contributor.rb +71 -0
  18. data/lib/relaton/bib/model/copyright.rb +27 -0
  19. data/lib/relaton/bib/model/date.rb +29 -0
  20. data/lib/relaton/bib/model/depiction.rb +14 -0
  21. data/lib/relaton/bib/model/docidentifier.rb +33 -0
  22. data/lib/relaton/bib/model/doctype.rb +14 -0
  23. data/lib/relaton/bib/model/edition.rb +14 -0
  24. data/lib/relaton/bib/model/editorial_group.rb +14 -0
  25. data/lib/relaton/bib/model/ext.rb +29 -0
  26. data/lib/relaton/bib/model/extent.rb +16 -0
  27. data/lib/relaton/bib/model/full_name_type.rb +64 -0
  28. data/lib/relaton/bib/model/fullname.rb +11 -0
  29. data/lib/relaton/bib/model/ics.rb +14 -0
  30. data/lib/relaton/bib/model/image.rb +28 -0
  31. data/lib/relaton/bib/model/item.rb +129 -0
  32. data/lib/relaton/bib/model/item_base.rb +19 -0
  33. data/lib/relaton/bib/model/keyword.rb +30 -0
  34. data/lib/relaton/bib/model/locality.rb +18 -0
  35. data/lib/relaton/bib/model/locality_stack.rb +14 -0
  36. data/lib/relaton/bib/model/localized_string.rb +57 -0
  37. data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
  38. data/lib/relaton/bib/model/logo.rb +12 -0
  39. data/lib/relaton/bib/model/medium.rb +22 -0
  40. data/lib/relaton/bib/model/note.rb +16 -0
  41. data/lib/relaton/bib/model/organization.rb +13 -0
  42. data/lib/relaton/bib/model/organization_type.rb +42 -0
  43. data/lib/relaton/bib/model/person.rb +36 -0
  44. data/lib/relaton/bib/model/phone.rb +14 -0
  45. data/lib/relaton/bib/model/place.rb +33 -0
  46. data/lib/relaton/bib/model/price.rb +14 -0
  47. data/lib/relaton/bib/model/relation.rb +43 -0
  48. data/lib/relaton/bib/model/series.rb +32 -0
  49. data/lib/relaton/bib/model/size.rb +23 -0
  50. data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
  51. data/lib/relaton/bib/model/status.rb +27 -0
  52. data/lib/relaton/bib/model/structured_identifier.rb +48 -0
  53. data/lib/relaton/bib/model/subdivision.rb +14 -0
  54. data/lib/relaton/bib/model/technical_committee.rb +14 -0
  55. data/lib/relaton/bib/model/title.rb +18 -0
  56. data/lib/relaton/bib/model/uri.rb +18 -0
  57. data/lib/relaton/bib/model/validity.rb +16 -0
  58. data/lib/relaton/bib/model/version.rb +14 -0
  59. data/lib/relaton/bib/model/workgroup.rb +20 -0
  60. data/lib/relaton/bib/parser/rfc_address.rb +60 -0
  61. data/lib/relaton/bib/parser/rfc_contacts.rb +35 -0
  62. data/lib/relaton/bib/parser/rfc_docidentifier.rb +70 -0
  63. data/lib/relaton/bib/parser/rfc_organization.rb +31 -0
  64. data/lib/relaton/bib/parser/rfc_person.rb +42 -0
  65. data/lib/relaton/bib/parser/rfc_reference.rb +143 -0
  66. data/lib/relaton/bib/parser/rfc_referencegroup.rb +45 -0
  67. data/lib/relaton/bib/parser/rfc_shared.rb +23 -0
  68. data/lib/relaton/bib/renderer/bibtex_builder.rb +348 -0
  69. data/lib/relaton/bib/renderer/rfc.rb +297 -0
  70. data/lib/relaton/bib/util.rb +18 -0
  71. data/lib/relaton/bib/version.rb +5 -0
  72. data/lib/{relaton_bib.rb → relaton/bib.rb} +47 -36
  73. data/lib/{relaton_bib → relaton}/bibtex_parser.rb +24 -27
  74. data/lib/{relaton_bib → relaton}/bibxml_parser.rb +43 -46
  75. data/lib/{relaton_bib → relaton}/hit.rb +3 -3
  76. data/lib/{relaton_bib → relaton}/hit_collection.rb +2 -2
  77. data/lib/{relaton_bib → relaton}/workers_pool.rb +1 -1
  78. data/lib/{relaton_bib → relaton}/xml_parser.rb +49 -51
  79. data/relaton-bib.gemspec +8 -8
  80. metadata +95 -74
  81. data/lib/relaton_bib/bib_item_locality.rb +0 -175
  82. data/lib/relaton_bib/biblio_note.rb +0 -72
  83. data/lib/relaton_bib/biblio_version.rb +0 -46
  84. data/lib/relaton_bib/bibliographic_date.rb +0 -119
  85. data/lib/relaton_bib/bibliographic_item.rb +0 -668
  86. data/lib/relaton_bib/bibliographic_size.rb +0 -103
  87. data/lib/relaton_bib/classification.rb +0 -40
  88. data/lib/relaton_bib/config.rb +0 -16
  89. data/lib/relaton_bib/contribution_info.rb +0 -117
  90. data/lib/relaton_bib/contributor.rb +0 -277
  91. data/lib/relaton_bib/copyright_association.rb +0 -79
  92. data/lib/relaton_bib/document_identifier.rb +0 -118
  93. data/lib/relaton_bib/document_relation.rb +0 -95
  94. data/lib/relaton_bib/document_relation_collection.rb +0 -57
  95. data/lib/relaton_bib/document_status.rb +0 -92
  96. data/lib/relaton_bib/document_type.rb +0 -52
  97. data/lib/relaton_bib/edition.rb +0 -55
  98. data/lib/relaton_bib/editorial_group.rb +0 -41
  99. data/lib/relaton_bib/extent.rb +0 -39
  100. data/lib/relaton_bib/forename.rb +0 -65
  101. data/lib/relaton_bib/formatted_ref.rb +0 -17
  102. data/lib/relaton_bib/formatted_string.rb +0 -133
  103. data/lib/relaton_bib/full_name.rb +0 -108
  104. data/lib/relaton_bib/hash_converter.rb +0 -568
  105. data/lib/relaton_bib/ics.rb +0 -42
  106. data/lib/relaton_bib/image.rb +0 -95
  107. data/lib/relaton_bib/localized_string.rb +0 -149
  108. data/lib/relaton_bib/medium.rb +0 -76
  109. data/lib/relaton_bib/organization.rb +0 -165
  110. data/lib/relaton_bib/person.rb +0 -129
  111. data/lib/relaton_bib/place.rb +0 -203
  112. data/lib/relaton_bib/renderer/bibtex_builder.rb +0 -312
  113. data/lib/relaton_bib/renderer/bibxml.rb +0 -296
  114. data/lib/relaton_bib/series.rb +0 -119
  115. data/lib/relaton_bib/structured_identifier.rb +0 -173
  116. data/lib/relaton_bib/technical_committee.rb +0 -34
  117. data/lib/relaton_bib/typed_title_string.rb +0 -191
  118. data/lib/relaton_bib/typed_uri.rb +0 -57
  119. data/lib/relaton_bib/util.rb +0 -16
  120. data/lib/relaton_bib/validity.rb +0 -52
  121. data/lib/relaton_bib/version.rb +0 -3
  122. data/lib/relaton_bib/workgroup.rb +0 -58
  123. /data/lib/{relaton_bib → relaton}/deep_dup.rb +0 -0
@@ -1,296 +0,0 @@
1
- module RelatonBib
2
- module Renderer
3
- class BibXML
4
- def initialize(bib)
5
- @bib = bib
6
- end
7
-
8
- #
9
- # Render BibXML (RFC)
10
- #
11
- # @param [Nokogiri::XML::Builder, nil] builder
12
- # @param [Boolean] include_keywords (false)
13
- #
14
- # @return [String, Nokogiri::XML::Builder::NodeBuilder] XML
15
- #
16
- def render(builder: nil, include_keywords: true)
17
- if builder
18
- render_bibxml builder, include_keywords
19
- else
20
- Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
21
- render_bibxml xml, include_keywords
22
- end.doc.root.to_xml
23
- end
24
- end
25
-
26
- #
27
- # Render BibXML (RFC, BCP)
28
- #
29
- # @param [Nokogiri::XML::Builder] builder
30
- # @param [Boolean] include_bibdata
31
- #
32
- def render_bibxml(builder, include_keywords) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
33
- target = @bib.link.detect { |l| l.type.casecmp("src").zero? } ||
34
- @bib.link.detect { |l| l.type.casecmp("doi").zero? }
35
- bxml = if @bib.docnumber&.match(/^BCP/) || (@bib.docidentifier.detect(&:primary)&.id ||
36
- @bib.docidentifier[0].id).include?("BCP")
37
- render_bibxml_refgroup(builder, include_keywords)
38
- else
39
- render_bibxml_ref(builder, include_keywords)
40
- end
41
- bxml[:target] = target.content.to_s if target
42
- end
43
-
44
- #
45
- # Render BibXML (BCP)
46
- #
47
- # @param [Nokogiri::XML::Builder] builder
48
- # @param [Boolean] include_keywords
49
- #
50
- def render_bibxml_refgroup(builder, include_keywords)
51
- builder.referencegroup(**ref_attrs) do |b|
52
- @bib.relation.each do |r|
53
- r.bibitem.to_bibxml(b, include_keywords: include_keywords) if r.type == "includes"
54
- end
55
- end
56
- end
57
-
58
- #
59
- # Render BibXML (RFC)
60
- #
61
- # @param [Nokogiri::XML::Builder] builder
62
- # @param [Boolean] include_keywords
63
- #
64
- def render_bibxml_ref(builder, include_keywords) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
65
- builder.reference(**ref_attrs) do |xml|
66
- if @bib.title.any? || @bib.contributor.any? || @bib.date.any? || @bib.abstract.any? ||
67
- @bib.editorialgroup&.technical_committee&.any? ||
68
- (include_keywords && @bib.keyword.any?)
69
- xml.front do
70
- xml.title @bib.title[0].title.content if @bib.title.any?
71
- render_authors xml
72
- render_date xml
73
- render_workgroup xml
74
- render_keyword xml if include_keywords
75
- render_abstract xml
76
- end
77
- end
78
- render_seriesinfo xml
79
- render_format xml
80
- end
81
- end
82
-
83
- #
84
- # Create reference attributes
85
- #
86
- # @return [Hash<Symbol=>String>] attributes
87
- #
88
- def ref_attrs # rubocop:disable Metrics/AbcSize
89
- discopes = %w[anchor docName number]
90
- attrs = @bib.docidentifier.each_with_object({}) do |di, h|
91
- next unless discopes.include?(di.scope)
92
-
93
- h[di.scope.to_sym] = di.id
94
- end
95
- return attrs if attrs.any?
96
-
97
- @bib.docidentifier.first&.tap do |di|
98
- anchor = di.type == "IANA" ? di.id.split[1..].join(" ").upcase : di.id
99
- return { anchor: anchor.gsub(" ", ".") }
100
- end
101
- end
102
-
103
- #
104
- # Render authors
105
- #
106
- # @param [Nokogiri::XML::Builder] builder xml builder
107
- #
108
- def render_authors(builder) # rubocop:disable Metrics/AbcSize
109
- @bib.contributor.each do |c|
110
- builder.author do |xml|
111
- xml.parent[:role] = "editor" if c.role.detect { |r| r.type == "editor" }
112
- if c.entity.is_a?(Person) then render_person xml, c.entity
113
- else render_organization xml, c.entity, c.role
114
- end
115
- render_address xml, c
116
- end
117
- end
118
- end
119
-
120
- #
121
- # Render address
122
- #
123
- # @param [Nokogiri::XML::Builder] builder xml builder
124
- # @param [RelatonBib::ContributionInfo] contrib contributor
125
- #
126
- def render_address(builder, contrib) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
127
- address, contact = address_contact contrib.entity.contact
128
- if address || contact.any?
129
- builder.address do |xml|
130
- # address = contrib.entity.contact.detect { |cn| cn.is_a? Address }
131
- if address
132
- xml.postal do
133
- xml.city address.city if address.city
134
- xml.code address.postcode if address.postcode
135
- xml.country address.country if address.country
136
- xml.region address.state if address.state
137
- xml.street address.street[0] if address.street.any?
138
- end
139
- end
140
- render_contact xml, contact
141
- end
142
- end
143
- end
144
-
145
- def address_contact(contact) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
146
- addr = contact.detect do |c|
147
- c.is_a?(Address) && (c.city || c.postcode || c.country || c.state || c.street.any?)
148
- end
149
- cont = contact.select { |c| c.is_a?(Contact) }
150
- [addr, cont]
151
- end
152
-
153
- #
154
- # Render contact
155
- #
156
- # @param [Nokogiri::XML::Builder] builder xml builder
157
- # @param [Array<RelatonBib::Address, RelatonBib::Contact>] addr contact
158
- #
159
- def render_contact(builder, addr)
160
- %w[phone email uri].each do |type|
161
- cont = addr.detect { |cn| cn.is_a?(Contact) && cn.type == type }
162
- builder.send type, cont.value if cont
163
- end
164
- end
165
-
166
- #
167
- # Render person
168
- #
169
- # @param [Nokogiri::XML::Builder] builder xml builder
170
- # @param [RelatonBib::Person] person person
171
- #
172
- def render_person(builder, person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
173
- render_organization builder, person.affiliation.first&.organization
174
- if person.name.completename
175
- builder.parent[:fullname] = person.name.completename.content
176
- elsif person.name.forename.any?
177
- builder.parent[:fullname] = person.name.forename.map do |n|
178
- n.content || n.initial
179
- end.join " "
180
- end
181
- if person.name.initials
182
- builder.parent[:initials] = person.name.initials.content
183
- elsif person.name.forename.any?
184
- builder.parent[:initials] = person.name.forename.map do |f|
185
- "#{f.initial || f.content[0]}."
186
- end.join
187
- end
188
- if person.name.surname
189
- if !person.name.completename && person.name.forename.any? && person.name.surname
190
- builder.parent[:fullname] += " #{person.name.surname}"
191
- end
192
- builder.parent[:surname] = person.name.surname.content
193
- end
194
- end
195
-
196
- #
197
- # Render organization
198
- #
199
- # @param [Nokogiri::XML::Builder] builder xml builder
200
- # @param [RelatonBib::Organization] org organization
201
- #
202
- def render_organization(builder, org, _role = []) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/AbcSize
203
- abbrev = org&.abbreviation&.content
204
- orgname = org&.name&.first&.content
205
- orgname = if BibXMLParser::ORGNAMES.key?(abbrev) then abbrev
206
- else BibXMLParser::ORGNAMES.key(orgname) || orgname || abbrev
207
- end
208
- # if role.detect { |r| r.description.detect { |d| d.content == "BibXML author" } }
209
- # builder.parent[:fullname] = orgname
210
- # else
211
- org = builder.organization orgname
212
- org[:abbrev] = abbrev if abbrev
213
- # end
214
- end
215
-
216
- #
217
- # Render date
218
- #
219
- # @param [Nokogiri::XML::Builder] builder xml builder
220
- #
221
- def render_date(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
222
- dt = @bib.date.detect { |d| d.type == "published" }
223
- return unless dt
224
-
225
- elm = builder.date
226
- y = dt.on(:year) || dt.from(:year) || dt.to(:year)
227
- elm[:year] = y if y
228
- m = dt.on(:month) || dt.from(:month) || dt.to(:month)
229
- elm[:month] = Date::MONTHNAMES[m] if m
230
- # rfcs = %w[RFC BCP FYI STD]
231
- # unless rfcs.include?(doctype) && docidentifier.detect { |di| rfcs.include? di.type }
232
- d = dt.on(:day) || dt.from(:day) || dt.to(:day)
233
- elm[:day] = d if d
234
- # end
235
- end
236
-
237
- #
238
- # Render workgroup
239
- #
240
- # @param [Nokogiri::XML::Builder] builder xml builder
241
- #
242
- def render_workgroup(builder)
243
- @bib.editorialgroup&.technical_committee&.each do |tc|
244
- builder.workgroup tc.workgroup.name
245
- end
246
- end
247
-
248
- #
249
- # Render keyword
250
- #
251
- # @param [Nokogiri::XML::Builder] builder xml builder
252
- #
253
- def render_keyword(builder)
254
- @bib.keyword.each { |kw| builder.keyword kw.content }
255
- end
256
-
257
- #
258
- # Render abstract
259
- #
260
- # @param [Nokogiri::XML::Builder] builder xml builder
261
- #
262
- def render_abstract(builder)
263
- return unless @bib.abstract.any?
264
-
265
- builder.abstract { |xml| xml << @bib.abstract[0].content.gsub(/(<\/?)p(>)/, '\1t\2') }
266
- end
267
-
268
- #
269
- # Render seriesinfo
270
- #
271
- # @param [Nokogiri::XML::Builder] builder xml builder
272
- #
273
- def render_seriesinfo(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
274
- @bib.docidentifier.each do |di|
275
- if BibXMLParser::SERIESINFONAMES.include?(di.type) && di.scope != "trademark"
276
- builder.seriesInfo(name: di.type, value: di.id)
277
- end
278
- end
279
- # di_types = docidentifier.map(&:type)
280
- @bib.series.select do |s|
281
- s.title && # !di_types.include?(s.title.title.to_s) &&
282
- !BibXMLParser::SERIESINFONAMES.include?(s.title.title.to_s)
283
- end.uniq { |s| s.title.title.to_s }.each do |s|
284
- si = builder.seriesInfo(name: s.title.title.to_s)
285
- si[:value] = s.number if s.number
286
- end
287
- end
288
-
289
- def render_format(builder)
290
- @bib.link.select { |l| l.type == "TXT" }.each do |l|
291
- builder.format type: l.type, target: l.content
292
- end
293
- end
294
- end
295
- end
296
- end
@@ -1,119 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RelatonBib
4
- #
5
- # Series class.
6
- #
7
- class Series
8
- # TYPES = %w[main alt].freeze
9
-
10
- # @return [String, nil] allowed values: "main" or "alt"
11
- attr_reader :type
12
-
13
- # @return [RelatonBib::FormattedRef, nil]
14
- attr_reader :formattedref
15
-
16
- # @return [RelatonBib::TypedTitleString] title
17
- attr_reader :title
18
-
19
- # @return [String, nil]
20
- attr_reader :place, :organization, :from, :to, :number, :partnumber, :run
21
-
22
- # @return [RelatonBib::LocalizedString, nil]
23
- attr_reader :abbreviation
24
-
25
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
26
-
27
- # @param type [String, nil]
28
- # @param formattedref [RelatonBib::FormattedRef, nil]
29
- # @param title [RelatonBib::TypedTitleString] title
30
- # @param place [String, nil]
31
- # @param orgaization [String, nil]
32
- # @param abbreviation [RelatonBib::LocalizedString, nil]
33
- # @param from [String, nil]
34
- # @param to [String, nil]
35
- # @param number [String, nil]
36
- # @param partnumber [String, nil]
37
- # @param run [String, nil]
38
- def initialize(**args)
39
- unless args[:title].is_a?(RelatonBib::TypedTitleString)
40
- raise ArgumentError, "argument `title` should present in series"
41
- end
42
-
43
- # if args[:type] && !TYPES.include?(args[:type])
44
- # warn "[relaton-bib] Series type is invalid: #{args[:type]}"
45
- # end
46
-
47
- @type = args[:type] # if %w[main alt].include? args[:type]
48
- @title = args[:title]
49
- @formattedref = args[:formattedref]
50
- @place = args[:place]
51
- @organization = args[:organization]
52
- @abbreviation = args[:abbreviation]
53
- @from = args[:from]
54
- @to = args[:to]
55
- @number = args[:number]
56
- @partnumber = args[:partnumber]
57
- @run = args[:run]
58
- end
59
- # rubocop:enable Metrics/MethodLength
60
-
61
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
62
-
63
- # @param builder [Nokogiri::XML::Builder]
64
- def to_xml(builder) # rubocop:disable Metrics/MethodLength
65
- xml = builder.series do
66
- formattedref&.to_xml builder
67
- builder.title { title.to_xml builder }
68
- builder.place place if place
69
- builder.organization organization if organization
70
- builder.abbreviation { abbreviation.to_xml builder } if abbreviation
71
- builder.from from if from
72
- builder.to to if to
73
- builder.number number if number
74
- builder.partnumber partnumber if partnumber
75
- builder.run run if run
76
- end
77
- xml[:type] = type if type
78
- end
79
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
80
- # rubocop:enable Metrics/PerceivedComplexity
81
-
82
- # @return [Hash]
83
- def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
84
- hash = {}
85
- hash["type"] = type if type
86
- hash["formattedref"] = formattedref.to_hash if formattedref
87
- hash["title"] = title.to_hash
88
- hash["place"] = place if place
89
- hash["organization"] = organization if organization
90
- hash["abbreviation"] = abbreviation.to_hash if abbreviation
91
- hash["from"] = from if from
92
- hash["to"] = to if to
93
- hash["number"] = number if number
94
- hash["partnumber"] = partnumber if partnumber
95
- hash["run"] = run if run
96
- hash
97
- end
98
-
99
- # @param prefix [String]
100
- # @param count [Integer]
101
- # @return [String]
102
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
103
- pref = prefix.empty? ? "series" : prefix + ".series"
104
- out = count > 1 ? "#{pref}::\n" : ""
105
- out += "#{pref}.type:: #{type}\n" if type
106
- out += formattedref.to_asciibib pref if formattedref
107
- out += title.to_asciibib pref
108
- out += "#{pref}.place:: #{place}\n" if place
109
- out += "#{pref}.organization:: #{organization}\n" if organization
110
- out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
111
- out += "#{pref}.from:: #{from}\n" if from
112
- out += "#{pref}.to:: #{to}\n" if to
113
- out += "#{pref}.number:: #{number}\n" if number
114
- out += "#{pref}.partnumber:: #{partnumber}\n" if partnumber
115
- out += "#{pref}.run:: #{run}\n" if run
116
- out
117
- end
118
- end
119
- end
@@ -1,173 +0,0 @@
1
- module RelatonBib
2
- class StructuredIdentifierCollection
3
- include RelatonBib
4
- extend Forwardable
5
-
6
- def_delegators :@collection, :any?, :size, :[], :detect, :map, :each,
7
- :reduce
8
-
9
- # @param collection [Array<RelatonBib::StructuredIdentifier>]
10
- def initialize(collection)
11
- @collection = collection
12
- end
13
-
14
- # @param builder [Nokogiri::XML::Builder]
15
- def to_xml(builder)
16
- @collection.each { |si| si.to_xml builder }
17
- end
18
-
19
- # @return [Array<Hash>]
20
- def to_hash
21
- single_element_array @collection
22
- end
23
-
24
- # @param prefix [String]
25
- # @return [String]
26
- def to_asciibib(prefix = "")
27
- pref = prefix.empty? ? prefix : prefix + "."
28
- pref += "structured_identifier"
29
- @collection.reduce("") do |out, si|
30
- out += "#{pref}::\n" if @collection.size > 1
31
- out + si.to_asciibib(pref)
32
- end
33
- end
34
-
35
- # remoe year from docnumber
36
- def remove_date
37
- @collection.each &:remove_date
38
- end
39
-
40
- def remove_part
41
- @collection.each &:remove_part
42
- end
43
-
44
- def all_parts
45
- @collection.each &:all_parts
46
- end
47
-
48
- def presence?
49
- any?
50
- end
51
-
52
- # @return [RelatonBib::StructuredIdentifierCollection]
53
- # def map(&block)
54
- # StructuredIdentifierCollection.new @collection.map &block
55
- # end
56
- end
57
-
58
- class StructuredIdentifier
59
- include RelatonBib
60
-
61
- # @return [String]
62
- attr_reader :docnumber
63
-
64
- # @return [Array<String>]
65
- attr_reader :agency
66
-
67
- # @return [String, nil]
68
- attr_reader :type, :klass, :partnumber, :edition, :version, :supplementtype,
69
- :supplementnumber, :language, :year
70
-
71
- # rubocop:disable Metrics/MethodLength
72
-
73
- # @param docnumber [String]
74
- # @param args [Hash]
75
- # @option args [String, nil] :type
76
- # @option args [Array<String>] :agency
77
- # @option args [Stirng, nil] :class
78
- # @option args [String, nil] :partnumber
79
- # @option args [String, nil] :edition
80
- # @option args [String, nil] :version
81
- # @option args [String, nil] :supplementtype
82
- # @option args [String, nil] :supplementnumber
83
- # @option args [String, nil] :language
84
- # @option args [String, nil] :year
85
- def initialize(docnumber:, **args)
86
- @type = args[:type]
87
- @agency = args[:agency]
88
- @klass = args[:class]
89
- @docnumber = docnumber
90
- @partnumber = args[:partnumber]
91
- @edition = args[:edition]
92
- @version = args[:version]
93
- @supplementtype = args[:supplementtype]
94
- @supplementnumber = args[:supplementnumber]
95
- @language = args[:language]
96
- @year = args[:year]
97
- end
98
-
99
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
100
-
101
- # @param builder [Nokogiri::XML::Builder]
102
- def to_xml(builder)
103
- xml = builder.structuredidentifier do |b|
104
- agency&.each { |a| b.agency a }
105
- b.class_ klass if klass
106
- b.docnumber docnumber
107
- b.partnumber partnumber if partnumber
108
- b.edition edition if edition
109
- b.version version if version
110
- b.supplementtype supplementtype if supplementtype
111
- b.supplementnumber supplementnumber if supplementnumber
112
- b.language language if language
113
- b.year year if year
114
- end
115
- xml[:type] = type if type
116
- end
117
-
118
- # @return [Hash]
119
- def to_hash
120
- hash = { "docnumber" => docnumber }
121
- hash["type"] = type if type
122
- hash["agency"] = single_element_array agency if agency&.any?
123
- hash["class"] = klass if klass
124
- hash["partnumber"] = partnumber if partnumber
125
- hash["edition"] = edition if edition
126
- hash["version"] = version if version
127
- hash["supplementtype"] = supplementtype if supplementtype
128
- hash["supplementnumber"] = supplementnumber if supplementnumber
129
- hash["language"] = language if language
130
- hash["year"] = year if year
131
- hash
132
- end
133
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
134
-
135
- # @param prefix [String]
136
- # @return [String]
137
- def to_asciibib(prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
138
- out = "#{prefix}.docnumber:: #{docnumber}\n"
139
- agency.each { |a| out += "#{prefix}.agency:: #{a}\n" }
140
- out += "#{prefix}.type:: #{type}\n" if type
141
- out += "#{prefix}.class:: #{klass}\n" if klass
142
- out += "#{prefix}.partnumber:: #{partnumber}\n" if partnumber
143
- out += "#{prefix}.edition:: #{edition}\n" if edition
144
- out += "#{prefix}.version:: #{version}\n" if version
145
- out += "#{prefix}.supplementtype:: #{supplementtype}\n" if supplementtype
146
- if supplementnumber
147
- out += "#{prefix}.supplementnumber:: #{supplementnumber}\n"
148
- end
149
- out += "#{prefix}.language:: #{language}\n" if language
150
- out += "#{prefix}.year:: #{year}\n" if year
151
- out
152
- end
153
-
154
- def remove_date
155
- if @type == "Chinese Standard"
156
- @docnumber.sub!(/-[12]\d\d\d/, "")
157
- else
158
- @docnumber.sub!(/:[12]\d\d\d/, "")
159
- end
160
- @year = nil
161
- end
162
-
163
- # in docid manipulations, assume ISO as the default: id-part:year
164
- def remove_part
165
- @partnumber = nil
166
- @docnumber = @docnumber.sub(/-\d+/, "")
167
- end
168
-
169
- def all_parts
170
- @docnumber = @docnumber + " (all parts)"
171
- end
172
- end
173
- end
@@ -1,34 +0,0 @@
1
- require "relaton_bib/workgroup"
2
-
3
- module RelatonBib
4
- class TechnicalCommittee
5
- # @return [RelatonBib::WorkGroup]
6
- attr_reader :workgroup
7
-
8
- # @param workgroup [RelatonBib::WorkGroup]
9
- def initialize(workgroup)
10
- @workgroup = workgroup
11
- end
12
-
13
- # @param builder [Nokogiri::XML::Builder]
14
- def to_xml(builder)
15
- builder.send(:"technical-committee") { |b| workgroup.to_xml b }
16
- end
17
-
18
- # @return [Hash]
19
- def to_hash
20
- workgroup.to_hash
21
- end
22
-
23
- # @param prefix [String]
24
- # @param count [Integer] number of technical committees
25
- # @return [String]
26
- def to_asciibib(prefix = "", count = 1)
27
- pref = prefix.empty? ? prefix : "#{prefix}."
28
- pref += "technical_committee"
29
- out = count > 1 ? "#{pref}::\n" : ""
30
- out += workgroup.to_asciibib pref
31
- out
32
- end
33
- end
34
- end