relaton-bib 1.4.0 → 2.1.7

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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/integration-tests.yml +54 -0
  3. data/.github/workflows/rake.yml +15 -0
  4. data/.github/workflows/release.yml +24 -0
  5. data/.gitignore +4 -1
  6. data/.rubocop.yml +3 -1
  7. data/CLAUDE.md +108 -0
  8. data/Gemfile +11 -0
  9. data/README.adoc +229 -314
  10. data/bin/console +1 -1
  11. data/docs/hash.adoc +132 -83
  12. data/lib/relaton/bib/converter/asciibib/to_asciibib.rb +663 -0
  13. data/lib/relaton/bib/converter/asciibib.rb +13 -0
  14. data/lib/relaton/bib/converter/bibtex/from_bibtex.rb +245 -0
  15. data/lib/relaton/bib/converter/bibtex/to_bibtex.rb +341 -0
  16. data/lib/relaton/bib/converter/bibtex.rb +23 -0
  17. data/lib/relaton/bib/converter/bibxml/from_rfcxml.rb +386 -0
  18. data/lib/relaton/bib/converter/bibxml/from_rfcxml_referencegroup.rb +71 -0
  19. data/lib/relaton/bib/converter/bibxml/to_rfcxml.rb +308 -0
  20. data/lib/relaton/bib/converter/bibxml/to_rfcxml_referencegroup.rb +52 -0
  21. data/lib/relaton/bib/converter/bibxml.rb +51 -0
  22. data/lib/relaton/bib/hash_parser_v1.rb +767 -0
  23. data/lib/relaton/bib/item_data.rb +229 -0
  24. data/lib/relaton/bib/model/abstract.rb +16 -0
  25. data/lib/relaton/bib/model/address.rb +22 -0
  26. data/lib/relaton/bib/model/affiliation.rb +16 -0
  27. data/lib/relaton/bib/model/bibdata.rb +9 -0
  28. data/lib/relaton/bib/model/bibdata_shared.rb +10 -0
  29. data/lib/relaton/bib/model/bibitem.rb +9 -0
  30. data/lib/relaton/bib/model/bibitem_shared.rb +10 -0
  31. data/lib/relaton/bib/model/contact.rb +14 -0
  32. data/lib/relaton/bib/model/contribution_info.rb +16 -0
  33. data/lib/relaton/bib/model/contributor.rb +29 -0
  34. data/lib/relaton/bib/model/copyright.rb +27 -0
  35. data/lib/relaton/bib/model/date.rb +29 -0
  36. data/lib/relaton/bib/model/depiction.rb +16 -0
  37. data/lib/relaton/bib/model/docidentifier.rb +34 -0
  38. data/lib/relaton/bib/model/doctype.rb +14 -0
  39. data/lib/relaton/bib/model/edition.rb +14 -0
  40. data/lib/relaton/bib/model/ext.rb +35 -0
  41. data/lib/relaton/bib/model/extent.rb +16 -0
  42. data/lib/relaton/bib/model/formattedref.rb +43 -0
  43. data/lib/relaton/bib/model/full_name_type.rb +64 -0
  44. data/lib/relaton/bib/model/fullname.rb +11 -0
  45. data/lib/relaton/bib/model/ics.rb +49 -0
  46. data/lib/relaton/bib/model/image.rb +28 -0
  47. data/lib/relaton/bib/model/item.rb +44 -0
  48. data/lib/relaton/bib/model/item_base.rb +20 -0
  49. data/lib/relaton/bib/model/item_shared.rb +88 -0
  50. data/lib/relaton/bib/model/keyword.rb +30 -0
  51. data/lib/relaton/bib/model/locality.rb +18 -0
  52. data/lib/relaton/bib/model/locality_stack.rb +14 -0
  53. data/lib/relaton/bib/model/localized_string.rb +48 -0
  54. data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
  55. data/lib/relaton/bib/model/logo.rb +14 -0
  56. data/lib/relaton/bib/model/medium.rb +22 -0
  57. data/lib/relaton/bib/model/note.rb +16 -0
  58. data/lib/relaton/bib/model/organization.rb +11 -0
  59. data/lib/relaton/bib/model/organization_type.rb +40 -0
  60. data/lib/relaton/bib/model/person.rb +36 -0
  61. data/lib/relaton/bib/model/phone.rb +14 -0
  62. data/lib/relaton/bib/model/place.rb +33 -0
  63. data/lib/relaton/bib/model/price.rb +14 -0
  64. data/lib/relaton/bib/model/relation.rb +41 -0
  65. data/lib/relaton/bib/model/series.rb +32 -0
  66. data/lib/relaton/bib/model/size.rb +23 -0
  67. data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
  68. data/lib/relaton/bib/model/status.rb +27 -0
  69. data/lib/relaton/bib/model/structured_identifier.rb +48 -0
  70. data/lib/relaton/bib/model/subdivision.rb +16 -0
  71. data/lib/relaton/bib/model/title.rb +56 -0
  72. data/lib/relaton/bib/model/type/plain_date.rb +16 -0
  73. data/lib/relaton/bib/model/type/string_date.rb +48 -0
  74. data/lib/relaton/bib/model/uri.rb +18 -0
  75. data/lib/relaton/bib/model/validity.rb +16 -0
  76. data/lib/relaton/bib/model/version.rb +43 -0
  77. data/lib/relaton/bib/model_autoload.rb +85 -0
  78. data/lib/relaton/bib/namespace_helper.rb +21 -0
  79. data/lib/relaton/bib/sanitizer.rb +74 -0
  80. data/lib/relaton/bib/util.rb +18 -0
  81. data/lib/relaton/bib/version.rb +5 -0
  82. data/lib/relaton/bib/versions.json +35 -0
  83. data/lib/relaton/bib.rb +41 -0
  84. data/relaton-bib.gemspec +12 -16
  85. metadata +118 -129
  86. data/.github/workflows/macos.yml +0 -38
  87. data/.github/workflows/ubuntu.yml +0 -39
  88. data/.github/workflows/windows.yml +0 -41
  89. data/grammars/basicdoc.rng +0 -986
  90. data/grammars/biblio.rng +0 -1237
  91. data/grammars/isodoc.rng +0 -1613
  92. data/grammars/reqt.rng +0 -165
  93. data/lib/relaton_bib/bib_item_locality.rb +0 -107
  94. data/lib/relaton_bib/biblio_note.rb +0 -44
  95. data/lib/relaton_bib/biblio_version.rb +0 -49
  96. data/lib/relaton_bib/bibliographic_date.rb +0 -90
  97. data/lib/relaton_bib/bibliographic_item.rb +0 -726
  98. data/lib/relaton_bib/bibtex_parser.rb +0 -245
  99. data/lib/relaton_bib/classification.rb +0 -40
  100. data/lib/relaton_bib/contribution_info.rb +0 -109
  101. data/lib/relaton_bib/contributor.rb +0 -215
  102. data/lib/relaton_bib/copyright_association.rb +0 -77
  103. data/lib/relaton_bib/deep_dup.rb +0 -30
  104. data/lib/relaton_bib/document_identifier.rb +0 -95
  105. data/lib/relaton_bib/document_relation.rb +0 -94
  106. data/lib/relaton_bib/document_relation_collection.rb +0 -46
  107. data/lib/relaton_bib/document_status.rb +0 -93
  108. data/lib/relaton_bib/editorial_group.rb +0 -41
  109. data/lib/relaton_bib/formatted_ref.rb +0 -17
  110. data/lib/relaton_bib/formatted_string.rb +0 -55
  111. data/lib/relaton_bib/hash_converter.rb +0 -497
  112. data/lib/relaton_bib/hit.rb +0 -46
  113. data/lib/relaton_bib/hit_collection.rb +0 -73
  114. data/lib/relaton_bib/ics.rb +0 -37
  115. data/lib/relaton_bib/localized_string.rb +0 -93
  116. data/lib/relaton_bib/medium.rb +0 -44
  117. data/lib/relaton_bib/organization.rb +0 -135
  118. data/lib/relaton_bib/person.rb +0 -206
  119. data/lib/relaton_bib/place.rb +0 -49
  120. data/lib/relaton_bib/series.rb +0 -134
  121. data/lib/relaton_bib/structured_identifier.rb +0 -171
  122. data/lib/relaton_bib/technical_committee.rb +0 -36
  123. data/lib/relaton_bib/typed_title_string.rb +0 -96
  124. data/lib/relaton_bib/typed_uri.rb +0 -47
  125. data/lib/relaton_bib/validity.rb +0 -52
  126. data/lib/relaton_bib/version.rb +0 -3
  127. data/lib/relaton_bib/workers_pool.rb +0 -43
  128. data/lib/relaton_bib/workgroup.rb +0 -46
  129. data/lib/relaton_bib/xml_parser.rb +0 -463
  130. data/lib/relaton_bib.rb +0 -44
@@ -1,726 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "relaton_bib/typed_uri"
4
- require "relaton_bib/document_identifier"
5
- require "relaton_bib/copyright_association"
6
- require "relaton_bib/formatted_string"
7
- require "relaton_bib/contribution_info"
8
- require "relaton_bib/bibliographic_date"
9
- require "relaton_bib/series"
10
- require "relaton_bib/document_status"
11
- require "relaton_bib/organization"
12
- require "relaton_bib/document_relation_collection"
13
- require "relaton_bib/typed_title_string"
14
- require "relaton_bib/formatted_ref"
15
- require "relaton_bib/medium"
16
- require "relaton_bib/classification"
17
- require "relaton_bib/validity"
18
- require "relaton_bib/document_relation"
19
- require "relaton_bib/bib_item_locality"
20
- require "relaton_bib/xml_parser"
21
- require "relaton_bib/bibtex_parser"
22
- require "relaton_bib/biblio_note"
23
- require "relaton_bib/biblio_version"
24
- require "relaton_bib/workers_pool"
25
- require "relaton_bib/hash_converter"
26
- require "relaton_bib/place"
27
- require "relaton_bib/structured_identifier"
28
- require "relaton_bib/editorial_group"
29
- require "relaton_bib/ics"
30
-
31
- module RelatonBib
32
- # Bibliographic item
33
- class BibliographicItem
34
- include RelatonBib
35
-
36
- TYPES = %W[article book booklet conference manual proceedings presentation
37
- thesis techreport standard unpublished map electronic\sresource
38
- audiovisual film video broadcast graphic_work music patent
39
- inbook incollection inproceedings journal].freeze
40
-
41
- # @return [TrueClass, FalseClass, NilClass]
42
- attr_accessor :all_parts
43
-
44
- # @return [String, NilClass]
45
- attr_reader :id, :type, :docnumber, :edition, :doctype
46
-
47
- # @!attribute [r] title
48
- # @return [Array<RelatonBib::TypedTitleString>]
49
-
50
- # @return [Array<RelatonBib::TypedUri>]
51
- attr_reader :link
52
-
53
- # @return [Array<RelatonBib::DocumentIdentifier>]
54
- attr_reader :docidentifier
55
-
56
- # @return [Array<RelatonBib::BibliographicDate>]
57
- attr_accessor :date
58
-
59
- # @return [Array<RelatonBib::ContributionInfo>]
60
- attr_reader :contributor
61
-
62
- # @return [RelatonBib::BibliongraphicItem::Version, NilClass]
63
- attr_reader :version
64
-
65
- # @return [Array<RelatonBib::BiblioNote>]
66
- attr_reader :biblionote
67
-
68
- # @return [Array<String>] language Iso639 code
69
- attr_reader :language
70
-
71
- # @return [Array<String>] script Iso15924 code
72
- attr_reader :script
73
-
74
- # @return [RelatonBib::FormattedRef, NilClass]
75
- attr_reader :formattedref
76
-
77
- # @!attribute [r] abstract
78
- # @return [Array<RelatonBib::FormattedString>]
79
-
80
- # @return [RelatonBib::DocumentStatus, NilClass]
81
- attr_reader :status
82
-
83
- # @return [Array<RelatonBib::CopyrightAssociation>]
84
- attr_reader :copyright
85
-
86
- # @return [RelatonBib::DocRelationCollection]
87
- attr_reader :relation
88
-
89
- # @return [Array<RelatonBib::Series>]
90
- attr_reader :series
91
-
92
- # @return [RelatonBib::Medium, NilClass]
93
- attr_reader :medium
94
-
95
- # @return [Array<RelatonBib::Place>]
96
- attr_reader :place
97
-
98
- # @return [Array<RelatonBib::BibItemLocality>]
99
- attr_reader :extent
100
-
101
- # @return [Array<Strig>]
102
- attr_reader :accesslocation, :license
103
-
104
- # @return [Array<Relaton::Classification>]
105
- attr_reader :classification
106
-
107
- # @return [RelatonBib:Validity, NilClass]
108
- attr_reader :validity
109
-
110
- # @return [Date]
111
- attr_reader :fetched
112
-
113
- # @return [Array<RelatonBib::LocalizedString>]
114
- attr_reader :keyword
115
-
116
- # @return [RelatonBib::EditorialGroup, nil]
117
- attr_reader :editorialgroup
118
-
119
- # @return [Array<RelatonBib:ICS>]
120
- attr_reader :ics
121
-
122
- # @return [RelatonBib::StructuredIdentifierCollection]
123
- attr_reader :structuredidentifier
124
-
125
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
126
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
127
-
128
- # @param id [String, NilClass]
129
- # @param title [Array<RelatonBib::TypedTitleString>]
130
- # @param formattedref [RelatonBib::FormattedRef, NilClass]
131
- # @param type [String, NilClass]
132
- # @param docid [Array<RelatonBib::DocumentIdentifier>]
133
- # @param docnumber [String, NilClass]
134
- # @param language [Arra<String>]
135
- # @param script [Array<String>]
136
- # @param docstatus [RelatonBib::DocumentStatus, NilClass]
137
- # @param edition [String, NilClass]
138
- # @param version [RelatonBib::BibliographicItem::Version, NilClass]
139
- # @param biblionote [Array<RelatonBib::BiblioNote>]
140
- # @param series [Array<RelatonBib::Series>]
141
- # @param medium [RelatonBib::Medium, NilClas]
142
- # @param place [Array<String, RelatonBib::Place>]
143
- # @param extent [Array<Relaton::BibItemLocality>]
144
- # @param accesslocation [Array<String>]
145
- # @param classification [Array<RelatonBib::Classification>]
146
- # @param validity [RelatonBib:Validity, NilClass]
147
- # @param fetched [Date, NilClass] default nil
148
- # @param keyword [Array<String>]
149
- # @param doctype [String]
150
- # @param editorialgroup [RelatonBib::EditorialGroup, nil]
151
- # @param ics [Array<RelatonBib::ICS>]
152
- # @param structuredidentifier [RelatonBib::StructuredIdentifierCollection]
153
- #
154
- # @param copyright [Array<Hash, RelatonBib::CopyrightAssociation>]
155
- # @option copyright [Array<Hash, RelatonBib::ContributionInfo>] :owner
156
- # @option copyright [String] :from
157
- # @option copyright [String, NilClass] :to
158
- # @option copyright [String, NilClass] :scope
159
- #
160
- # @param date [Array<Hash>]
161
- # @option date [String] :type
162
- # @option date [String] :from
163
- # @option date [String] :to
164
- #
165
- # @param contributor [Array<Hash>]
166
- # @option contributor [RealtonBib::Organization, RelatonBib::Person]
167
- # @option contributor [String] :type
168
- # @option contributor [String] :from
169
- # @option contributor [String] :to
170
- # @option contributor [String] :abbreviation
171
- # @option contributor [Array<Array<String,Array<String>>>] :role
172
- #
173
- # @param abstract [Array<Hash, RelatonBib::FormattedString>]
174
- # @option abstract [String] :content
175
- # @option abstract [String] :language
176
- # @option abstract [String] :script
177
- # @option abstract [String] :type
178
- #
179
- # @param relation [Array<Hash>]
180
- # @option relation [String] :type
181
- # @option relation [RelatonBib::BibliographicItem,
182
- # RelatonIso::IsoBibliographicItem] :bibitem
183
- # @option relation [Array<RelatonBib::Locality,
184
- # RelatonBib::LocalityStack>] :locality
185
- # @option relation [Array<RelatonBib::SourceLocality,
186
- # RelatonBib::SourceLocalityStack>] :source_locality
187
- #
188
- # @param link [Array<Hash, RelatonBib::TypedUri>]
189
- # @option link [String] :type
190
- # @option link [String] :content
191
- def initialize(**args)
192
- if args[:type] && !TYPES.include?(args[:type])
193
- warn %{[relaton-bib] document type "#{args[:type]}" is invalid.}
194
- end
195
-
196
- @title = (args[:title] || []).map do |t|
197
- t.is_a?(Hash) ? TypedTitleString.new(t) : t
198
- end
199
-
200
- @date = (args[:date] || []).map do |d|
201
- d.is_a?(Hash) ? BibliographicDate.new(d) : d
202
- end
203
-
204
- @contributor = (args[:contributor] || []).map do |c|
205
- if c.is_a? Hash
206
- e = c[:entity].is_a?(Hash) ? Organization.new(c[:entity]) : c[:entity]
207
- ContributionInfo.new(entity: e, role: c[:role])
208
- else c
209
- end
210
- end
211
-
212
- @abstract = (args[:abstract] || []).map do |a|
213
- a.is_a?(Hash) ? FormattedString.new(a) : a
214
- end
215
-
216
- @copyright = args.fetch(:copyright, []).map do |c|
217
- c.is_a?(Hash) ? CopyrightAssociation.new(c) : c
218
- end
219
-
220
- @docidentifier = args[:docid] || []
221
- @formattedref = args[:formattedref] if title.empty?
222
- @id = args[:id] || makeid(nil, false)
223
- @type = args[:type]
224
- @docnumber = args[:docnumber]
225
- @edition = args[:edition]
226
- @version = args[:version]
227
- @biblionote = args.fetch :biblionote, []
228
- @language = args.fetch :language, []
229
- @script = args.fetch :script, []
230
- @status = args[:docstatus]
231
- @relation = DocRelationCollection.new(args[:relation] || [])
232
- @link = args.fetch(:link, []).map do |s|
233
- if s.is_a?(Hash) then TypedUri.new(s)
234
- elsif s.is_a?(String) then TypedUri.new(content: s)
235
- else s
236
- end
237
- end
238
- @series = args.fetch :series, []
239
- @medium = args[:medium]
240
- @place = args.fetch(:place, []).map do |pl|
241
- pl.is_a?(String) ? Place.new(name: pl) : pl
242
- end
243
- @extent = args[:extent] || []
244
- @accesslocation = args.fetch :accesslocation, []
245
- @classification = args.fetch :classification, []
246
- @validity = args[:validity]
247
- # we should pass the fetched arg from scrappers
248
- @fetched = args.fetch :fetched, nil
249
- @keyword = (args[:keyword] || []).map do |kw|
250
- LocalizedString.new(kw)
251
- end
252
- @license = args.fetch :license, []
253
- @doctype = args[:doctype]
254
- @editorialgroup = args[:editorialgroup]
255
- @ics = args.fetch :ics, []
256
- @structuredidentifier = args[:structuredidentifier]
257
- end
258
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
259
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
260
-
261
- # @param lang [String] language code Iso639
262
- # @return [RelatonBib::FormattedString, Array<RelatonBib::FormattedString>]
263
- def abstract(lang: nil)
264
- if lang
265
- @abstract.detect { |a| a.language.include? lang }
266
- else
267
- @abstract
268
- end
269
- end
270
-
271
- # @param id [RelatonBib::DocumentIdentifier]
272
- # @param attribute [boolean, nil]
273
- # @return [String]
274
- def makeid(id, attribute)
275
- return nil if attribute && !@id_attribute
276
-
277
- id ||= @docidentifier.reject { |i| i.type == "DOI" }[0]
278
- return unless id
279
-
280
- # contribs = publishers.map { |p| p&.entity&.abbreviation }.join '/'
281
- # idstr = "#{contribs}#{delim}#{id.project_number}"
282
- # idstr = id.project_number.to_s
283
- idstr = id.id.gsub(/:/, "-").gsub /\s/, ""
284
- # if id.part_number&.size&.positive? then idstr += "-#{id.part_number}"
285
- idstr.strip
286
- end
287
-
288
- # @param identifier [RelatonBib::DocumentIdentifier]
289
- # @param options [Hash]
290
- # @option options [boolean, nil] :no_year
291
- # @option options [boolean, nil] :all_parts
292
- # @return [String]
293
- def shortref(identifier, **opts) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
294
- pubdate = date.select { |d| d.type == "published" }
295
- year = if opts[:no_year] || pubdate.empty? then ""
296
- else ":" + pubdate&.first&.on&.year.to_s
297
- end
298
- year += ": All Parts" if opts[:all_parts] || @all_parts
299
-
300
- "#{makeid(identifier, false)}#{year}"
301
- end
302
-
303
- # @param builder [Nokogiri::XML::Builder, NillClass] (nil)
304
- # @return [String]
305
- def to_xml(builder = nil, **opts, &block)
306
- if builder
307
- render_xml builder, **opts, &block
308
- else
309
- Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
310
- render_xml xml, **opts, &block
311
- end.doc.root.to_xml
312
- end
313
- end
314
-
315
- # @return [Hash]
316
- def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
317
- hash = {}
318
- hash["id"] = id if id
319
- hash["title"] = single_element_array(title) if title&.any?
320
- hash["link"] = single_element_array(link) if link&.any?
321
- hash["type"] = type if type
322
- hash["docid"] = single_element_array(docidentifier) if docidentifier&.any?
323
- hash["docnumber"] = docnumber if docnumber
324
- hash["date"] = single_element_array(date) if date&.any?
325
- if contributor&.any?
326
- hash["contributor"] = single_element_array(contributor)
327
- end
328
- hash["edition"] = edition if edition
329
- hash["version"] = version.to_hash if version
330
- hash["revdate"] = revdate if revdate
331
- hash["biblionote"] = single_element_array(biblionote) if biblionote&.any?
332
- hash["language"] = single_element_array(language) if language&.any?
333
- hash["script"] = single_element_array(script) if script&.any?
334
- hash["formattedref"] = formattedref.to_hash if formattedref
335
- hash["abstract"] = single_element_array(abstract) if abstract&.any?
336
- hash["docstatus"] = status.to_hash if status
337
- hash["copyright"] = single_element_array(copyright) if copyright&.any?
338
- hash["relation"] = single_element_array(relation) if relation&.any?
339
- hash["series"] = single_element_array(series) if series&.any?
340
- hash["medium"] = medium.to_hash if medium
341
- hash["place"] = single_element_array(place) if place&.any?
342
- hash["extent"] = single_element_array(extent) if extent&.any?
343
- if accesslocation&.any?
344
- hash["accesslocation"] = single_element_array(accesslocation)
345
- end
346
- if classification&.any?
347
- hash["classification"] = single_element_array(classification)
348
- end
349
- hash["validity"] = validity.to_hash if validity
350
- hash["fetched"] = fetched.to_s if fetched
351
- hash["keyword"] = single_element_array(keyword) if keyword&.any?
352
- hash["license"] = single_element_array(license) if license&.any?
353
- hash["doctype"] = doctype if doctype
354
- if editorialgroup&.presence?
355
- hash["editorialgroup"] = editorialgroup.to_hash
356
- end
357
- hash["ics"] = single_element_array ics if ics.any?
358
- if structuredidentifier&.presence?
359
- hash["structuredidentifier"] = structuredidentifier.to_hash
360
- end
361
- hash
362
- end
363
-
364
- # @param bibtex [BibTeX::Bibliography, NilClass]
365
- # @return [String]
366
- def to_bibtex(bibtex = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
367
- item = BibTeX::Entry.new
368
- item.type = bibtex_type
369
- item.key = id
370
- bibtex_title item
371
- item.edition = edition if edition
372
- bibtex_author item
373
- bibtex_contributor item
374
- item.address = place.first.name if place.any?
375
- bibtex_note item
376
- bibtex_relation item
377
- bibtex_extent item
378
- bibtex_date item
379
- bibtex_series item
380
- bibtex_classification item
381
- item.keywords = keyword.map(&:content).join(", ") if keyword.any?
382
- bibtex_docidentifier item
383
- item.timestamp = fetched.to_s if fetched
384
- bibtex_link item
385
- bibtex ||= BibTeX::Bibliography.new
386
- bibtex << item
387
- bibtex.to_s
388
- end
389
-
390
- # @param lang [String] language code Iso639
391
- # @return [Array<RelatonIsoBib::TypedTitleString>]
392
- def title(lang: nil)
393
- if lang then @title.select { |t| t.title.language&.include? lang }
394
- else @title
395
- end
396
- end
397
-
398
- # @param type [Symbol] type of url, can be :src/:obp/:rss
399
- # @return [String]
400
- def url(type = :src)
401
- @link.detect { |s| s.type == type.to_s }.content.to_s
402
- end
403
-
404
- def abstract=(value)
405
- @abstract = value
406
- end
407
-
408
- def deep_clone
409
- dump = Marshal.dump self
410
- Marshal.load dump # rubocop:disable Security/MarshalLoad
411
- end
412
-
413
- def disable_id_attribute
414
- @id_attribute = false
415
- end
416
-
417
- # remove title part components and abstract
418
- def to_all_parts # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
419
- me = deep_clone
420
- me.disable_id_attribute
421
- me.relation << DocumentRelation.new(type: "instance", bibitem: self)
422
- me.language.each do |l|
423
- me.title.delete_if { |t| t.type == "title-part" }
424
- ttl = me.title.select do |t|
425
- t.type != "main" && t.title.language&.include?(l)
426
- end
427
- tm_en = ttl.map { |t| t.title.content }.join " – "
428
- me.title.detect do |t|
429
- t.type == "main" && t.title.language&.include?(l)
430
- end&.title&.content = tm_en
431
- end
432
- me.abstract = []
433
- me.docidentifier.each(&:remove_part)
434
- me.docidentifier.each(&:all_parts)
435
- me.structuredidentifier.remove_part
436
- me.structuredidentifier.all_parts
437
- me.docidentifier.each &:remove_date
438
- me.structuredidentifier&.remove_date
439
- me.all_parts = true
440
- me
441
- end
442
-
443
- # convert ISO:yyyy reference to reference to most recent
444
- # instance of reference, removing date-specific infomration:
445
- # date of publication, abstracts. Make dated reference Instance relation
446
- # of the redacated document
447
- def to_most_recent_reference
448
- me = deep_clone
449
- disable_id_attribute
450
- me.relation << DocumentRelation.new(type: "instance", bibitem: self)
451
- me.abstract = []
452
- me.date = []
453
- me.docidentifier.each &:remove_date
454
- me.structuredidentifier&.remove_date
455
- me.id&.sub! /-[12]\d\d\d/, ""
456
- me
457
- end
458
-
459
- # If revision_date exists then returns it else returns published date or nil
460
- # @return [String, NilClass]
461
- def revdate # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
462
- @revdate ||= if version&.revision_date
463
- version.revision_date
464
- else
465
- date.detect { |d| d.type == "published" }&.on&.to_s
466
- end
467
- end
468
-
469
- # @param prefix [String]
470
- # @return [String]
471
- def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
472
- pref = prefix.empty? ? prefix : prefix + "."
473
- out = prefix.empty? ? "[%bibitem]\n== {blank}\n" : ""
474
- out += "#{pref}id:: #{id}\n" if id
475
- out += "#{pref}fetched:: #{fetched}\n" if fetched
476
- title.each { |t| out += t.to_asciibib(prefix, title.size) }
477
- out += "#{pref}type:: #{type}\n" if type
478
- docidentifier.each do |di|
479
- out += di.to_asciibib prefix, docidentifier.size
480
- end
481
- out += "#{pref}docnumber:: #{docnumber}\n" if docnumber
482
- out += "#{pref}edition:: #{edition}\n" if edition
483
- language.each { |l| out += "#{pref}language:: #{l}\n" }
484
- script.each { |s| out += "#{pref}script:: #{s}\n" }
485
- out += version.to_asciibib prefix if version
486
- biblionote&.each { |b| out += b.to_asciibib prefix, biblionote.size }
487
- out += status.to_asciibib prefix if status
488
- date.each { |d| out += d.to_asciibib prefix, date.size }
489
- abstract.each do |a|
490
- out += a.to_asciibib "#{pref}abstract", abstract.size
491
- end
492
- copyright.each { |c| out += c.to_asciibib prefix, copyright.size }
493
- link.each { |l| out += l.to_asciibib prefix, link.size }
494
- out += medium.to_asciibib prefix if medium
495
- place.each { |pl| out += pl.to_asciibib prefix, place.size }
496
- extent.each { |ex| out += ex.to_asciibib "#{pref}extent", extent.size }
497
- accesslocation.each { |al| out += "#{pref}accesslocation:: #{al}\n" }
498
- classification.each do |cl|
499
- out += cl.to_asciibib prefix, classification.size
500
- end
501
- out += validity.to_asciibib prefix if validity
502
- contributor.each do |c|
503
- out += c.to_asciibib "contributor.*", contributor.size
504
- end
505
- out += relation.to_asciibib prefix if relation
506
- series.each { |s| out += s.to_asciibib prefix, series.size }
507
- out += "#{pref}doctype:: #{doctype}\n" if doctype
508
- out += "#{pref}formattedref:: #{formattedref}\n" if formattedref
509
- keyword.each { |kw| out += kw.to_asciibib "#{pref}keyword", keyword.size }
510
- out += editorialgroup.to_asciibib prefix if editorialgroup
511
- ics.each { |i| out += i.to_asciibib prefix, ics.size }
512
- out += structuredidentifier.to_asciibib prefix if structuredidentifier
513
- out
514
- end
515
-
516
- private
517
-
518
- # @return [String]
519
- def bibtex_title(item)
520
- title.each do |t|
521
- case t.type
522
- when "main" then item.tile = t.title.content
523
- end
524
- end
525
- end
526
-
527
- # @return [String]
528
- def bibtex_type
529
- case type
530
- when "standard", nil then "misc"
531
- else type
532
- end
533
- end
534
-
535
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
536
-
537
- # @param [BibTeX::Entry]
538
- def bibtex_author(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
539
- authors = contributor.select do |c|
540
- c.entity.is_a?(Person) && c.role.map(&:type).include?("author")
541
- end.map &:entity
542
-
543
- return unless authors.any?
544
-
545
- item.author = authors.map do |a|
546
- if a.name.surname
547
- "#{a.name.surname}, #{a.name.forename.map(&:to_s).join(' ')}"
548
- else
549
- a.name.completename.to_s
550
- end
551
- end.join " and "
552
- end
553
-
554
- # @param [BibTeX::Entry]
555
- def bibtex_contributor(item) # rubocop:disable Metrics/CyclomaticComplexity
556
- contributor.each do |c|
557
- rls = c.role.map(&:type)
558
- if rls.include?("publisher") then item.publisher = c.entity.name
559
- elsif rls.include?("distributor")
560
- case type
561
- when "techreport" then item.institution = c.entity.name
562
- when "inproceedings", "conference", "manual", "proceedings"
563
- item.organization = c.entity.name
564
- when "mastersthesis", "phdthesis" then item.school = c.entity.name
565
- end
566
- end
567
- end
568
- end
569
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
570
-
571
- # @param [BibTeX::Entry]
572
- def bibtex_note(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize
573
- biblionote.each do |n|
574
- case n.type
575
- when "annote" then item.annote = n.content
576
- when "howpublished" then item.howpublished = n.content
577
- when "comment" then item.comment = n.content
578
- when "tableOfContents" then item.content = n.content
579
- when nil then item.note = n.content
580
- end
581
- end
582
- end
583
-
584
- # @param [BibTeX::Entry]
585
- def bibtex_relation(item)
586
- rel = relation.detect { |r| r.type == "partOf" }
587
- if rel
588
- title_main = rel.bibitem.title.detect { |t| t.type == "main" }
589
- item.booktitle = title_main.title.content
590
- end
591
- end
592
-
593
- # @param [BibTeX::Entry]
594
- def bibtex_extent(item)
595
- extent.each do |e|
596
- case e.type
597
- when "chapter" then item.chapter = e.reference_from
598
- when "page"
599
- value = e.reference_from
600
- value += "-#{e.reference_to}" if e.reference_to
601
- item.pages = value
602
- when "volume" then item.volume = e.reference_from
603
- end
604
- end
605
- end
606
-
607
- # @param [BibTeX::Entry]
608
- def bibtex_date(item)
609
- date.each do |d|
610
- case d.type
611
- when "published"
612
- item.year = d.on.year
613
- item.month = d.on.month
614
- when "accessed" then item.urldate = d.on.to_s
615
- end
616
- end
617
- end
618
-
619
- # @param [BibTeX::Entry]
620
- def bibtex_series(item)
621
- series.each do |s|
622
- case s.type
623
- when "journal"
624
- item.journal = s.title.title
625
- item.number = s.number if s.number
626
- when nil then item.series = s.title.title
627
- end
628
- end
629
- end
630
-
631
- # @param [BibTeX::Entry]
632
- def bibtex_classification(item)
633
- classification.each do |c|
634
- case c.type
635
- when "type" then item["type"] = c.value
636
- # when "keyword" then item.keywords = c.value
637
- when "mendeley" then item["mendeley-tags"] = c.value
638
- end
639
- end
640
- end
641
-
642
- # @param [BibTeX::Entry]
643
- def bibtex_docidentifier(item)
644
- docidentifier.each do |i|
645
- case i.type
646
- when "isbn" then item.isbn = i.id
647
- when "lccn" then item.lccn = i.id
648
- when "issn" then item.issn = i.id
649
- end
650
- end
651
- end
652
-
653
- # @param [BibTeX::Entry]
654
- def bibtex_link(item)
655
- link.each do |l|
656
- case l.type
657
- when "doi" then item.doi = l.content
658
- when "file" then item.file2 = l.content
659
- when "src" then item.url = l.content
660
- end
661
- end
662
- end
663
-
664
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
665
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
666
- # rubocop:disable Style/NestedParenthesizedCalls, Metrics/BlockLength
667
-
668
- # @param builder [Nokogiri::XML::Builder]
669
- # @return [String]
670
- def render_xml(builder, **opts)
671
- root = opts[:bibdata] ? :bibdata : :bibitem
672
- xml = builder.send(root) do
673
- builder.fetched fetched if fetched
674
- title.each { |t| builder.title { t.to_xml builder } }
675
- formattedref&.to_xml builder
676
- link.each { |s| s.to_xml builder }
677
- docidentifier.each { |di| di.to_xml builder }
678
- builder.docnumber docnumber if docnumber
679
- date.each { |d| d.to_xml builder, **opts }
680
- contributor.each do |c|
681
- builder.contributor do
682
- c.role.each { |r| r.to_xml builder }
683
- c.to_xml builder
684
- end
685
- end
686
- builder.edition edition if edition
687
- version&.to_xml builder
688
- biblionote.each { |n| n.to_xml builder }
689
- opts[:note]&.each do |n|
690
- builder.note(n[:text], format: "text/plain", type: n[:type])
691
- end
692
- language.each { |l| builder.language l }
693
- script.each { |s| builder.script s }
694
- abstract.each { |a| builder.abstract { a.to_xml(builder) } }
695
- status&.to_xml builder
696
- copyright&.each { |c| c.to_xml builder }
697
- relation.each { |r| r.to_xml builder, **opts }
698
- series.each { |s| s.to_xml builder }
699
- medium&.to_xml builder
700
- place.each { |pl| pl.to_xml builder }
701
- extent.each { |e| builder.extent { e.to_xml builder } }
702
- accesslocation.each { |al| builder.accesslocation al }
703
- license.each { |l| builder.license l }
704
- classification.each { |cls| cls.to_xml builder }
705
- keyword.each { |kw| builder.keyword { kw.to_xml(builder) } }
706
- validity&.to_xml builder
707
- if block_given? then yield builder
708
- elsif opts[:bibdata] && (doctype || editorialgroup || ics&.any? ||
709
- structuredidentifier&.presence?)
710
- builder.ext do |b|
711
- b.doctype doctype if doctype
712
- editorialgroup&.to_xml b
713
- ics.each { |i| i.to_xml b }
714
- structuredidentifier&.to_xml b
715
- end
716
- end
717
- end
718
- xml[:id] = id if id && !opts[:bibdata] && !opts[:embedded]
719
- xml[:type] = type if type
720
- xml
721
- end
722
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
723
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
724
- # rubocop:enable Style/NestedParenthesizedCalls, Metrics/BlockLength
725
- end
726
- end