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,245 +0,0 @@
1
- require "bibtex"
2
- require "iso639"
3
-
4
- module RelatonBib
5
- class BibtexParser
6
- class << self
7
- # @param bibtex [String]
8
- # @return [Hash{String=>RelatonBib::BibliographicItem}]
9
- def from_bibtex(bibtex)
10
- BibTeX.parse(bibtex).reduce({}) do |h, bt|
11
- h[bt.key] = BibliographicItem.new(
12
- id: bt.key,
13
- docid: fetch_docid(bt),
14
- fetched: fetch_fetched(bt),
15
- type: fetch_type(bt),
16
- title: fetch_title(bt),
17
- contributor: fetch_contributor(bt),
18
- date: fetch_date(bt),
19
- place: fetch_place(bt),
20
- biblionote: fetch_note(bt),
21
- relation: fetch_relation(bt),
22
- extent: fetch_extent(bt),
23
- edition: bt["edition"]&.to_s,
24
- series: fetch_series(bt),
25
- link: fetch_link(bt),
26
- language: fetch_language(bt),
27
- classification: fetch_classification(bt),
28
- keyword: fetch_keyword(bt)
29
- )
30
- h
31
- end
32
- end
33
-
34
- private
35
-
36
- # @param bibtex [BibTeX::Entry]
37
- # @return [Array<RelatonBib::DocumentIdentifier>]
38
- def fetch_docid(bibtex)
39
- docid = []
40
- docid << DocumentIdentifier.new(id: bibtex.isbn.to_s, type: "isbn") if bibtex["isbn"]
41
- docid << DocumentIdentifier.new(id: bibtex.lccn.to_s, type: "lccn") if bibtex["lccn"]
42
- docid << DocumentIdentifier.new(id: bibtex.issn.to_s, type: "issn") if bibtex["issn"]
43
- docid
44
- end
45
-
46
- # @param bibtex [BibTeX::Entry]
47
- # @return [String, NilClass]
48
- def fetch_fetched(bibtex)
49
- Date.parse(bibtex.timestamp.to_s) if bibtex["timestamp"]
50
- end
51
-
52
- # @param bibtex [BibTeX::Entry]
53
- # @return [String]
54
- def fetch_type(bibtex)
55
- case bibtex.type
56
- when :mastersthesis, :phdthesis then "thesis"
57
- when :conference then "inproceedings"
58
- when :misc then "standard"
59
- else bibtex.type.to_s
60
- end
61
- end
62
-
63
- # @param bibtex [BibTeX::Entry]
64
- # @return [Array<Hash>]
65
- def fetch_place(bibtex)
66
- bibtex["address"] ? [bibtex.address.to_s] : []
67
- end
68
-
69
- # @param bibtex [BibTeX::Entry]
70
- # @return [Array<Hash>]
71
- def fetch_title(bibtex)
72
- title = []
73
- title << { type: "main", content: bibtex.title.to_s } if bibtex["title"]
74
- title << { type: "main", content: bibtex.subtitle.to_s } if bibtex["subtitle"]
75
- title
76
- end
77
-
78
- # @param bibtex [BibTeX::Entry]
79
- # @return [Array<Hash>]
80
- def fetch_contributor(bibtex)
81
- contributor = []
82
- fetch_person(bibtex["author"]).each do |entity|
83
- contributor << { entity: entity, role: [{ type: "author" }] }
84
- end
85
-
86
- fetch_person(bibtex["editor"]).each do |entity|
87
- contributor << { entity: entity, role: [{ type: "editor" }] }
88
- end
89
-
90
- if bibtex["publisher"]
91
- contributor << { entity: { name: bibtex.publisher.to_s }, role: [{ type: "publisher" }] }
92
- end
93
-
94
- if bibtex["institution"]
95
- contributor << {
96
- entity: { name: bibtex.institution.to_s },
97
- role: [{ type: "distributor", description: ["sponsor"] }]
98
- }
99
- end
100
-
101
- if bibtex["organization"]
102
- contributor << {
103
- entity: { name: bibtex.organization.to_s },
104
- role: [{ type: "distributor", description: ["sponsor"] }]
105
- }
106
- end
107
-
108
- if bibtex["school"]
109
- contributor << {
110
- entity: { name: bibtex.school.to_s },
111
- role: [{ type: "distributor", description: ["sponsor"] }]
112
- }
113
- end
114
- contributor
115
- end
116
-
117
- # @param bibtex [BibTeX::Entry]
118
- # @return [Array<RelatonBib::Person>]
119
- def fetch_person(person)
120
- return [] unless person
121
-
122
- person.map do |name|
123
- parts = name.split ", "
124
- surname = LocalizedString.new parts.first
125
- fname = parts.size > 1 ? parts[1].split : []
126
- forename = fname.map { |fn| LocalizedString.new fn }
127
- Person.new name: FullName.new(surname: surname, forename: forename)
128
- end
129
- end
130
-
131
- # @param bibtex [BibTeX::Entry]
132
- # @return [Array<Hash>]
133
- def fetch_date(bibtex)
134
- date = []
135
- if bibtex["year"]
136
- on = Date.new(bibtex.year.to_i, bibtex["month_numeric"]&.to_i || 1).to_s
137
- date << { type: "published", on: on }
138
- end
139
-
140
- if bibtex["urldate"]
141
- date << { type: "accessed", on: Date.parse(bibtex.urldate.to_s).to_s }
142
- end
143
-
144
- date
145
- end
146
-
147
- # @param bibtex [BibTeX::Entry]
148
- # @return [Array<RelatonBib::BiblioNote>]
149
- def fetch_note(bibtex)
150
- bibtex.select do |k, _v|
151
- %i[annote howpublished comment note content].include? k
152
- end.reduce([]) do |mem, note|
153
- type = case note[0]
154
- when :note then nil
155
- when :content then "tableOfContents"
156
- else note[0].to_s
157
- end
158
- mem << BiblioNote.new(type: type, content: note[1].to_s)
159
- end
160
- end
161
-
162
- # @param bibtex [BibTeX::Entry]
163
- # @return [Array<Hash>]
164
- def fetch_relation(bibtex)
165
- return [] unless bibtex["booktitle"]
166
-
167
- title = TypedTitleString.new(type: "main", content: bibtex.booktitle.to_s)
168
- [{ type: "partOf", bibitem: BibliographicItem.new(title: [title]) }]
169
- end
170
-
171
- # @param bibtex [BibTeX::Entry]
172
- # @return [Array<RelatonBib::BibItemLocality>]
173
- def fetch_extent(bibtex)
174
- bibtex.select do |k, _v|
175
- %i[chapter pages volume].include? k
176
- end.reduce([]) do |mem, loc|
177
- if loc[0] == :pages
178
- type = "page"
179
- from, to = loc[1].to_s.split "-"
180
- else
181
- type = loc[0].to_s
182
- from = loc[1].to_s
183
- to = nil
184
- end
185
- mem << BibItemLocality.new(type, from, to)
186
- end
187
- end
188
-
189
- # @param bibtex [BibTeX::Entry]
190
- # @return [Array<RelatonBib::Series>]
191
- def fetch_series(bibtex)
192
- series = []
193
- if bibtex["journal"]
194
- series << Series.new(
195
- type: "journal",
196
- title: TypedTitleString.new(content: bibtex.journal.to_s),
197
- number: bibtex["number"]&.to_s,
198
- )
199
- end
200
-
201
- if bibtex["series"]
202
- title = TypedTitleString.new content: bibtex.series.to_s
203
- series << Series.new(title: title)
204
- end
205
- series
206
- end
207
-
208
- # @param bibtex [BibTeX::Entry]
209
- # @return [Array<RelatonBib::TypedUri>]
210
- def fetch_link(bibtex)
211
- link = []
212
- link << TypedUri.new(type: "src", content: bibtex.url.to_s) if bibtex["url"]
213
- link << TypedUri.new(type: "doi", content: bibtex.doi.to_s) if bibtex["doi"]
214
- link << TypedUri.new(type: "file", content: bibtex.file2.to_s) if bibtex["file2"]
215
- link
216
- end
217
-
218
- # @param bibtex [BibTeX::Entry]
219
- # @return [Array<String>]
220
- def fetch_language(bibtex)
221
- return [] unless bibtex["language"]
222
-
223
- [Iso639[bibtex.language.to_s].alpha2]
224
- end
225
-
226
- # @param bibtex [BibTeX::Entry]
227
- # @return [RelatonBib::Classification, NilClass]
228
- def fetch_classification(bibtex)
229
- cls = []
230
- cls << Classification.new(type: "type", value: bibtex["type"].to_s) if bibtex["type"]
231
- # cls << Classification.new(type: "keyword", value: bibtex.keywords.to_s) if bibtex["keywords"]
232
- if bibtex["mendeley-tags"]
233
- cls << Classification.new(type: "mendeley", value: bibtex["mendeley-tags"].to_s)
234
- end
235
- cls
236
- end
237
-
238
- # @param bibtex [BibTeX::Entry]
239
- # @return [Array<String>]
240
- def fetch_keyword(bibtex)
241
- bibtex["keywords"]&.split(", ") || []
242
- end
243
- end
244
- end
245
- end
@@ -1,40 +0,0 @@
1
- module RelatonBib
2
- class Classification
3
- # @return [String, NilClass]
4
- attr_reader :type
5
-
6
- # @return [String]
7
- attr_reader :value
8
-
9
- # @param type [String, NilClass]
10
- # @param value [String]
11
- def initialize(type: nil, value:)
12
- @type = type
13
- @value = value
14
- end
15
-
16
- # @param builder [Nokogiri::XML::Builder]
17
- def to_xml(builder)
18
- xml = builder.classification value
19
- xml[:type] = type if type
20
- end
21
-
22
- # @return [Hash]
23
- def to_hash
24
- hash = { "value" => value }
25
- hash["type"] = type if type
26
- hash
27
- end
28
-
29
- # @param prefix [String]
30
- # @param count [Integer] number of classifications
31
- # @return [String]
32
- def to_asciibib(prefix = "", count = 1)
33
- pref = prefix.empty? ? "classification" : prefix + ".classification"
34
- out = count > 1 ? "#{pref}::\n" : ""
35
- out += "#{pref}.type:: #{type}\n" if type
36
- out += "#{pref}.value:: #{value}\n"
37
- out
38
- end
39
- end
40
- end
@@ -1,109 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "relaton_bib/person"
4
-
5
- # RelatonBib module
6
- module RelatonBib
7
- # Contributor's role.
8
- class ContributorRole
9
- include RelatonBib
10
-
11
- TYPES = %w[author performer publisher editor adapter translator
12
- distributor].freeze
13
-
14
- # @return [Array<RelatonBib::FormattedString>]
15
- attr_reader :description
16
-
17
- # @return [Strig]
18
- attr_reader :type
19
-
20
- # @param type [String] allowed types "author", "editor",
21
- # "cartographer", "publisher"
22
- # @param description [Array<String>]
23
- def initialize(**args)
24
- if args[:type] && !TYPES.include?(args[:type])
25
- warn %{[relaton-bib] Contributor's type "#{args[:type]}" is invalid.}
26
- end
27
-
28
- @type = args[:type]
29
- @description = args.fetch(:description, []).map do |d|
30
- FormattedString.new content: d, format: nil
31
- end
32
- end
33
-
34
- # @param builder [Nokogiri::XML::Builder]
35
- def to_xml(builder)
36
- builder.role(type: type) do
37
- description.each do |d|
38
- builder.description { |desc| d.to_xml(desc) }
39
- end
40
- end
41
- end
42
-
43
- # @return [Hash, String]
44
- def to_hash
45
- if description&.any?
46
- hash = { "description" => single_element_array(description) }
47
- hash["type"] = type if type
48
- hash
49
- elsif type
50
- type
51
- end
52
- end
53
-
54
- # @param prefix [String]
55
- # @param count [Integer] number of contributors
56
- # 2return [String]
57
- def to_asciibib(prefix = "", count = 1)
58
- pref = prefix.empty? ? prefix : prefix + "."
59
- out = count > 1 ? "#{prefix}::\n" : ""
60
- description.each do |d|
61
- out += d.to_asciibib "#{pref}role.description", description.size
62
- end
63
- out += "#{pref}role.type:: #{type}\n" if type
64
- out
65
- end
66
- end
67
-
68
- # Contribution info.
69
- class ContributionInfo
70
- include RelatonBib
71
-
72
- # @return [Array<RelatonBib::ContributorRole>]
73
- attr_reader :role
74
-
75
- # @return
76
- # [RelatonBib::Person, RelatonBib::Organization]
77
- attr_reader :entity
78
-
79
- # @param entity [RelatonBib::Person, RelatonBib::Organization]
80
- # @param role [Array<String>]
81
- def initialize(entity:, role: [{ type: "publisher" }])
82
- @entity = entity
83
- @role = role.map { |r| ContributorRole.new(**r) }
84
- end
85
-
86
- # @param builder [Nokogiri::XML::Builder]
87
- def to_xml(builder)
88
- entity.to_xml builder
89
- end
90
-
91
- # @return [Hash]
92
- def to_hash
93
- hash = entity.to_hash
94
- hash["role"] = single_element_array(role) if role&.any?
95
- hash
96
- end
97
-
98
- # @param prefix [String]
99
- # @param count [Integer] number of contributors
100
- # @return [String]
101
- def to_asciibib(prefix = "", count = 1)
102
- pref = prefix.split(".").first
103
- out = count > 1 ? "#{pref}::\n" : ""
104
- out += entity.to_asciibib prefix
105
- role.each { |r| out += r.to_asciibib pref, role.size }
106
- out
107
- end
108
- end
109
- end
@@ -1,215 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "uri"
4
-
5
- module RelatonBib
6
- # Address class.
7
- class Address
8
- # @return [Array<String>]
9
- attr_reader :street
10
-
11
- # @return [String]
12
- attr_reader :city
13
-
14
- # @return [String, NilClass]
15
- attr_reader :state
16
-
17
- # @return [String]
18
- attr_reader :country
19
-
20
- # @return [String, NilClass]
21
- attr_reader :postcode
22
-
23
- # @param street [Array<String>]
24
- # @param city [String]
25
- # @param state [String]
26
- # @param country [String]
27
- # @param postcode [String]
28
- def initialize(street:, city:, state: nil, country:, postcode: nil)
29
- @street = street
30
- @city = city
31
- @state = state
32
- @country = country
33
- @postcode = postcode
34
- end
35
-
36
- # @param builder [Nokogiri::XML::Document]
37
- def to_xml(doc)
38
- doc.address do
39
- street.each { |str| doc.street str }
40
- doc.city city
41
- doc.state state if state
42
- doc.country country
43
- doc.postcode postcode if postcode
44
- end
45
- end
46
-
47
- # @return [Hash]
48
- def to_hash
49
- hash = {}
50
- hash["street"] = street if street&.any?
51
- hash["city"] = city
52
- hash["state"] = state if state
53
- hash["country"] = country
54
- hash["postcode"] = postcode if postcode
55
- hash
56
- end
57
-
58
- # @param prefix [String]
59
- # @param count [Integer] number of addresses
60
- # @return [String]
61
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
62
- pref = prefix.empty? ? "address" : prefix + ".address"
63
- out = count > 1 ? "#{pref}::\n" : ""
64
- street.each { |st| out += "#{pref}.street:: #{st}\n" }
65
- out += "#{pref}.city:: #{city}\n"
66
- out += "#{pref}.state:: #{state}\n" if state
67
- out += "#{pref}.country:: #{country}\n"
68
- out += "#{pref}.postcode:: #{postcode}\n" if postcode
69
- out
70
- end
71
- end
72
-
73
- # Contact class.
74
- class Contact
75
- # @return [String] allowed "phone", "email" or "uri"
76
- attr_reader :type
77
-
78
- # @return [String]
79
- attr_reader :value
80
-
81
- # @param type [String] allowed "phone", "email" or "uri"
82
- # @param value [String]
83
- def initialize(type:, value:)
84
- @type = type
85
- @value = value
86
- end
87
-
88
- # @param builder [Nokogiri::XML::Document]
89
- def to_xml(doc)
90
- doc.send type, value
91
- end
92
-
93
- # @return [Hash]
94
- def to_hash
95
- { "type" => type, "value" => value }
96
- end
97
-
98
- # @param prefix [String]
99
- # @param count [Integer] number of contacts
100
- # @return [string]
101
- def to_asciibib(prefix = "", count = 1)
102
- pref = prefix.empty? ? prefix : prefix + "."
103
- out = count > 1 ? "#{pref}contact::\n" : ""
104
- out += "#{pref}contact.type:: #{type}\n"
105
- out += "#{pref}contact.value:: #{value}\n"
106
- out
107
- end
108
- end
109
-
110
- # Affiliation.
111
- class Affiliation
112
- include RelatonBib
113
-
114
- # @return [RelatonBib::LocalizedString, NilClass]
115
- attr_reader :name
116
-
117
- # @return [Array<RelatonBib::FormattedString>]
118
- attr_reader :description
119
-
120
- # @return [RelatonBib::Organization]
121
- attr_reader :organization
122
-
123
- # @param organization [RelatonBib::Organization]
124
- # @param name [RelatonBib::LocalizedString, NilClass]
125
- # @param description [Array<RelatonBib::FormattedString>]
126
- def initialize(organization:, name: nil, description: [])
127
- @name = name
128
- @organization = organization
129
- @description = description
130
- end
131
-
132
- # @params builder [Nokogiri::XML::Builder]
133
- def to_xml(builder)
134
- builder.affiliation do
135
- builder.name { name.to_xml builder } if name
136
- description.each { |d| builder.description { d.to_xml builder } }
137
- organization.to_xml builder
138
- end
139
- end
140
-
141
- # @return [Hash]
142
- def to_hash
143
- hash = organization.to_hash
144
- hash["name"] = name.to_hash if name
145
- if description&.any?
146
- hash["description"] = single_element_array(description)
147
- end
148
- hash
149
- end
150
-
151
- # @param prefix [String]
152
- # @param count [Integer]
153
- # @return [String]
154
- def to_asciibib(prefix = "", count = 1)
155
- pref = prefix.empty? ? prefix : prefix + "."
156
- out = count > 1 ? "#{pref}affiliation::\n" : ""
157
- out += name.to_asciibib "#{pref}affiliation.name" if name
158
- description.each do |d|
159
- out += d.to_asciibib "#{pref}affiliation.description", description.size
160
- end
161
- out += organization.to_asciibib "#{pref}affiliation.*"
162
- out
163
- end
164
- end
165
-
166
- # Contributor.
167
- class Contributor
168
- include RelatonBib
169
-
170
- # @return [URI]
171
- attr_reader :uri
172
-
173
- # @return [Array<RelatonBib::Address, RelatonBib::Contact>]
174
- attr_reader :contact
175
-
176
- # @param url [String, NilClass]
177
- # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
178
- def initialize(url: nil, contact: [])
179
- @uri = URI url if url
180
- @contact = contact
181
- end
182
-
183
- # Returns url.
184
- # @return [String]
185
- def url
186
- @uri.to_s
187
- end
188
-
189
- # @params builder [Nokogiri::XML::Builder]
190
- def to_xml(builder)
191
- contact.each { |contact| contact.to_xml builder }
192
- end
193
-
194
- # @return [Hash]
195
- def to_hash
196
- hash = {}
197
- hash["url"] = uri.to_s if uri
198
- hash["contact"] = single_element_array(contact) if contact&.any?
199
- hash
200
- end
201
-
202
- # @param prefix [String]
203
- # @return [String]
204
- def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
205
- pref = prefix.empty? ? prefix : prefix + "."
206
- out = ""
207
- out += "#{pref}url:: #{uri}\n" if uri
208
- addr = contact.select { |c| c.is_a? RelatonBib::Address }
209
- addr.each { |ct| out += ct.to_asciibib prefix, addr.size }
210
- cont = contact.select { |c| c.is_a? RelatonBib::Contact }
211
- cont.each { |ct| out += ct.to_asciibib prefix, cont.size }
212
- out
213
- end
214
- end
215
- end
@@ -1,77 +0,0 @@
1
- module RelatonBib
2
- # Copyright association.
3
- class CopyrightAssociation
4
- include RelatonBib
5
-
6
- # @return [Date]
7
- attr_reader :from
8
-
9
- # @return [Date, NilClass]
10
- attr_reader :to
11
-
12
- # @return [String, NilClass]
13
- attr_reader :scope
14
-
15
- # @return [Array<RelatonBib::ContributionInfo>]
16
- attr_reader :owner
17
-
18
- # rubocop:disable Metrics/AbcSize
19
-
20
- # @param owner [Array<Hash, RelatonBib::ContributionInfo>] contributor
21
- # @option owner [String] :name
22
- # @option owner [String] :abbreviation
23
- # @option owner [String] :url
24
- # @param from [String] date
25
- # @param to [String, NilClass] date
26
- # @param scope [String, NilClass]
27
- def initialize(owner:, from:, to: nil, scope: nil)
28
- unless owner.any?
29
- raise ArgumentError, "at least one owner should exist."
30
- end
31
-
32
- @owner = owner.map do |o|
33
- o.is_a?(Hash) ? ContributionInfo.new(entity: Organization.new(o)) : o
34
- end
35
-
36
- @from = Date.strptime(from.to_s, "%Y") if from.to_s.match? /\d{4}/
37
- @to = Date.strptime(to.to_s, "%Y") unless to.to_s.empty?
38
- @scope = scope
39
- end
40
-
41
- # @param builder [Nokogiri::XML::Builder]
42
- def to_xml(builder)
43
- builder.copyright do
44
- builder.from from ? from.year : "unknown"
45
- builder.to to.year if to
46
- owner.each { |o| builder.owner { o.to_xml builder } }
47
- builder.scope scope if scope
48
- end
49
- end
50
- # rubocop:enable Metrics/AbcSize
51
-
52
- # @return [Hash]
53
- def to_hash
54
- owners = single_element_array(owner.map { |o| o.to_hash["organization"] })
55
- hash = {
56
- "owner" => owners,
57
- "from" => from.year.to_s,
58
- }
59
- hash["to"] = to.year.to_s if to
60
- hash["scope"] = scope if scope
61
- hash
62
- end
63
-
64
- # @param prefix [String]
65
- # @param count [Iteger] number of copyright elements
66
- # @return [String]
67
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
68
- pref = prefix.empty? ? "copyright" : prefix + ".copyright"
69
- out = count > 1 ? "#{pref}::\n" : ""
70
- owner.each { |ow| out += ow.to_asciibib "#{pref}.owner", owner.size }
71
- out += "#{pref}.from:: #{from.year}\n" if from
72
- out += "#{pref}.to:: #{to.year}\n" if to
73
- out += "#{pref}.scope:: #{scope}\n" if scope
74
- out
75
- end
76
- end
77
- end