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.
- checksums.yaml +4 -4
- data/.github/workflows/integration-tests.yml +54 -0
- data/.github/workflows/rake.yml +15 -0
- data/.github/workflows/release.yml +24 -0
- data/.gitignore +4 -1
- data/.rubocop.yml +3 -1
- data/CLAUDE.md +108 -0
- data/Gemfile +11 -0
- data/README.adoc +229 -314
- data/bin/console +1 -1
- data/docs/hash.adoc +132 -83
- data/lib/relaton/bib/converter/asciibib/to_asciibib.rb +663 -0
- data/lib/relaton/bib/converter/asciibib.rb +13 -0
- data/lib/relaton/bib/converter/bibtex/from_bibtex.rb +245 -0
- data/lib/relaton/bib/converter/bibtex/to_bibtex.rb +341 -0
- data/lib/relaton/bib/converter/bibtex.rb +23 -0
- data/lib/relaton/bib/converter/bibxml/from_rfcxml.rb +386 -0
- data/lib/relaton/bib/converter/bibxml/from_rfcxml_referencegroup.rb +71 -0
- data/lib/relaton/bib/converter/bibxml/to_rfcxml.rb +308 -0
- data/lib/relaton/bib/converter/bibxml/to_rfcxml_referencegroup.rb +52 -0
- data/lib/relaton/bib/converter/bibxml.rb +51 -0
- data/lib/relaton/bib/hash_parser_v1.rb +767 -0
- data/lib/relaton/bib/item_data.rb +229 -0
- data/lib/relaton/bib/model/abstract.rb +16 -0
- data/lib/relaton/bib/model/address.rb +22 -0
- data/lib/relaton/bib/model/affiliation.rb +16 -0
- data/lib/relaton/bib/model/bibdata.rb +9 -0
- data/lib/relaton/bib/model/bibdata_shared.rb +10 -0
- data/lib/relaton/bib/model/bibitem.rb +9 -0
- data/lib/relaton/bib/model/bibitem_shared.rb +10 -0
- data/lib/relaton/bib/model/contact.rb +14 -0
- data/lib/relaton/bib/model/contribution_info.rb +16 -0
- data/lib/relaton/bib/model/contributor.rb +29 -0
- data/lib/relaton/bib/model/copyright.rb +27 -0
- data/lib/relaton/bib/model/date.rb +29 -0
- data/lib/relaton/bib/model/depiction.rb +16 -0
- data/lib/relaton/bib/model/docidentifier.rb +34 -0
- data/lib/relaton/bib/model/doctype.rb +14 -0
- data/lib/relaton/bib/model/edition.rb +14 -0
- data/lib/relaton/bib/model/ext.rb +35 -0
- data/lib/relaton/bib/model/extent.rb +16 -0
- data/lib/relaton/bib/model/formattedref.rb +43 -0
- data/lib/relaton/bib/model/full_name_type.rb +64 -0
- data/lib/relaton/bib/model/fullname.rb +11 -0
- data/lib/relaton/bib/model/ics.rb +49 -0
- data/lib/relaton/bib/model/image.rb +28 -0
- data/lib/relaton/bib/model/item.rb +44 -0
- data/lib/relaton/bib/model/item_base.rb +20 -0
- data/lib/relaton/bib/model/item_shared.rb +88 -0
- data/lib/relaton/bib/model/keyword.rb +30 -0
- data/lib/relaton/bib/model/locality.rb +18 -0
- data/lib/relaton/bib/model/locality_stack.rb +14 -0
- data/lib/relaton/bib/model/localized_string.rb +48 -0
- data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
- data/lib/relaton/bib/model/logo.rb +14 -0
- data/lib/relaton/bib/model/medium.rb +22 -0
- data/lib/relaton/bib/model/note.rb +16 -0
- data/lib/relaton/bib/model/organization.rb +11 -0
- data/lib/relaton/bib/model/organization_type.rb +40 -0
- data/lib/relaton/bib/model/person.rb +36 -0
- data/lib/relaton/bib/model/phone.rb +14 -0
- data/lib/relaton/bib/model/place.rb +33 -0
- data/lib/relaton/bib/model/price.rb +14 -0
- data/lib/relaton/bib/model/relation.rb +41 -0
- data/lib/relaton/bib/model/series.rb +32 -0
- data/lib/relaton/bib/model/size.rb +23 -0
- data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
- data/lib/relaton/bib/model/status.rb +27 -0
- data/lib/relaton/bib/model/structured_identifier.rb +48 -0
- data/lib/relaton/bib/model/subdivision.rb +16 -0
- data/lib/relaton/bib/model/title.rb +56 -0
- data/lib/relaton/bib/model/type/plain_date.rb +16 -0
- data/lib/relaton/bib/model/type/string_date.rb +48 -0
- data/lib/relaton/bib/model/uri.rb +18 -0
- data/lib/relaton/bib/model/validity.rb +16 -0
- data/lib/relaton/bib/model/version.rb +43 -0
- data/lib/relaton/bib/model_autoload.rb +85 -0
- data/lib/relaton/bib/namespace_helper.rb +21 -0
- data/lib/relaton/bib/sanitizer.rb +74 -0
- data/lib/relaton/bib/util.rb +18 -0
- data/lib/relaton/bib/version.rb +5 -0
- data/lib/relaton/bib/versions.json +35 -0
- data/lib/relaton/bib.rb +41 -0
- data/relaton-bib.gemspec +12 -16
- metadata +118 -129
- data/.github/workflows/macos.yml +0 -38
- data/.github/workflows/ubuntu.yml +0 -39
- data/.github/workflows/windows.yml +0 -41
- data/grammars/basicdoc.rng +0 -986
- data/grammars/biblio.rng +0 -1237
- data/grammars/isodoc.rng +0 -1613
- data/grammars/reqt.rng +0 -165
- data/lib/relaton_bib/bib_item_locality.rb +0 -107
- data/lib/relaton_bib/biblio_note.rb +0 -44
- data/lib/relaton_bib/biblio_version.rb +0 -49
- data/lib/relaton_bib/bibliographic_date.rb +0 -90
- data/lib/relaton_bib/bibliographic_item.rb +0 -726
- data/lib/relaton_bib/bibtex_parser.rb +0 -245
- data/lib/relaton_bib/classification.rb +0 -40
- data/lib/relaton_bib/contribution_info.rb +0 -109
- data/lib/relaton_bib/contributor.rb +0 -215
- data/lib/relaton_bib/copyright_association.rb +0 -77
- data/lib/relaton_bib/deep_dup.rb +0 -30
- data/lib/relaton_bib/document_identifier.rb +0 -95
- data/lib/relaton_bib/document_relation.rb +0 -94
- data/lib/relaton_bib/document_relation_collection.rb +0 -46
- data/lib/relaton_bib/document_status.rb +0 -93
- data/lib/relaton_bib/editorial_group.rb +0 -41
- data/lib/relaton_bib/formatted_ref.rb +0 -17
- data/lib/relaton_bib/formatted_string.rb +0 -55
- data/lib/relaton_bib/hash_converter.rb +0 -497
- data/lib/relaton_bib/hit.rb +0 -46
- data/lib/relaton_bib/hit_collection.rb +0 -73
- data/lib/relaton_bib/ics.rb +0 -37
- data/lib/relaton_bib/localized_string.rb +0 -93
- data/lib/relaton_bib/medium.rb +0 -44
- data/lib/relaton_bib/organization.rb +0 -135
- data/lib/relaton_bib/person.rb +0 -206
- data/lib/relaton_bib/place.rb +0 -49
- data/lib/relaton_bib/series.rb +0 -134
- data/lib/relaton_bib/structured_identifier.rb +0 -171
- data/lib/relaton_bib/technical_committee.rb +0 -36
- data/lib/relaton_bib/typed_title_string.rb +0 -96
- data/lib/relaton_bib/typed_uri.rb +0 -47
- data/lib/relaton_bib/validity.rb +0 -52
- data/lib/relaton_bib/version.rb +0 -3
- data/lib/relaton_bib/workers_pool.rb +0 -43
- data/lib/relaton_bib/workgroup.rb +0 -46
- data/lib/relaton_bib/xml_parser.rb +0 -463
- data/lib/relaton_bib.rb +0 -44
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
# This class represents the data of a bibliographic item.
|
|
4
|
+
# It needed to keep data fot different types of representations (bibitem, bibdata ...).
|
|
5
|
+
# @TODO: remove this class when Lutaml Model will support transformation between different types of models.
|
|
6
|
+
class ItemData
|
|
7
|
+
include Core::ArrayWrapper
|
|
8
|
+
include NamespaceHelper
|
|
9
|
+
|
|
10
|
+
ATTRIBUTES = %i[
|
|
11
|
+
type schema_version fetched formattedref docnumber edition status
|
|
12
|
+
medium size validity ext
|
|
13
|
+
].freeze
|
|
14
|
+
COLLECTION_ATTRBUTES = %i[
|
|
15
|
+
date contributor version note language locale script
|
|
16
|
+
copyright series place price extent accesslocation license
|
|
17
|
+
classification keyword depiction
|
|
18
|
+
].freeze
|
|
19
|
+
COLLECTION_WRITE_ONLY_ATTRIBUTES = %i[title abstract source relation].freeze
|
|
20
|
+
|
|
21
|
+
ATTRIBUTES.each { |attr| attr_accessor attr }
|
|
22
|
+
COLLECTION_ATTRBUTES.each { |attr| attr_accessor attr }
|
|
23
|
+
COLLECTION_WRITE_ONLY_ATTRIBUTES.each { |attr| attr_writer attr }
|
|
24
|
+
|
|
25
|
+
attr_reader :id, :docidentifier
|
|
26
|
+
|
|
27
|
+
def initialize(**args)
|
|
28
|
+
ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", args[attr]) }
|
|
29
|
+
|
|
30
|
+
(COLLECTION_ATTRBUTES + COLLECTION_WRITE_ONLY_ATTRIBUTES).each do |attr|
|
|
31
|
+
instance_variable_set("@#{attr}", args[attr] || [])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
@docidentifier = args[:docidentifier] || []
|
|
35
|
+
self.schema_version = schema
|
|
36
|
+
@id = args[:id]
|
|
37
|
+
create_id
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def id=(value)
|
|
41
|
+
@id = value if value
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def docidentifier=(value)
|
|
45
|
+
@docidentifier = value || []
|
|
46
|
+
create_id
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
#
|
|
50
|
+
# Fetch schema version
|
|
51
|
+
#
|
|
52
|
+
# @return [String] schema version
|
|
53
|
+
#
|
|
54
|
+
def schema
|
|
55
|
+
@schema ||= Relaton.schema_versions["relaton-models"]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def to_relation_item
|
|
59
|
+
self.id = nil
|
|
60
|
+
self.schema_version = nil
|
|
61
|
+
self.fetched = nil
|
|
62
|
+
ext&.schema_version = nil
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# remove title part components and abstract
|
|
66
|
+
def to_all_parts # rubocop:disable Metrics/MethodLength
|
|
67
|
+
me = deep_clone
|
|
68
|
+
me.relation ||= []
|
|
69
|
+
to_relation_item
|
|
70
|
+
me.relation << create_relation(type: "instanceOf", bibitem: self)
|
|
71
|
+
me.delete_title_part!
|
|
72
|
+
me.title_update_main
|
|
73
|
+
me.abstract = []
|
|
74
|
+
me.docidentifier.each(&:to_all_parts!)
|
|
75
|
+
me.ext_to_all_parts!
|
|
76
|
+
# me.all_parts = true
|
|
77
|
+
me
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def to_most_recent_reference
|
|
81
|
+
me = deep_clone
|
|
82
|
+
to_relation_item
|
|
83
|
+
me.relation ||= []
|
|
84
|
+
me.relation << create_relation(type: "instanceOf", bibitem: self)
|
|
85
|
+
me.abstract = []
|
|
86
|
+
me.date = []
|
|
87
|
+
me.docidentifier.each(&:remove_date!)
|
|
88
|
+
me.ext_remove_date
|
|
89
|
+
me.create_id without_date: true
|
|
90
|
+
me
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def create_id(without_date: false)
|
|
94
|
+
return id if id && !id.empty?
|
|
95
|
+
|
|
96
|
+
docid = find_primary_docid
|
|
97
|
+
return unless docid
|
|
98
|
+
|
|
99
|
+
pubid = without_date ? docid.content.sub(/:\d{4}$/, "") : docid.content
|
|
100
|
+
self.id = pubid.to_s.gsub(/\W+/, "")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def title(lang = nil)
|
|
104
|
+
return @title if lang.nil?
|
|
105
|
+
|
|
106
|
+
@title.select { |t| t.language == lang.to_s }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def abstract(lang = nil)
|
|
110
|
+
return @abstract if lang.nil?
|
|
111
|
+
|
|
112
|
+
@abstract.select { |a| a.language == lang.to_s }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def source(src = nil)
|
|
116
|
+
return @source if src.nil?
|
|
117
|
+
|
|
118
|
+
@source.find { |s| s.type == src.to_s }&.content
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def relation(type = nil)
|
|
122
|
+
return @relation if type.nil?
|
|
123
|
+
|
|
124
|
+
@relation&.select { |r| r.type == type.to_s }
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def to_xml(bibdata: false, **opts)
|
|
128
|
+
add_notes opts[:note] do
|
|
129
|
+
bibdata ? namespace::Bibdata.to_xml(self) : namespace::Bibitem.to_xml(self)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def to_yaml(**opts)
|
|
134
|
+
add_notes opts[:note] do
|
|
135
|
+
namespace::Item.to_yaml(self)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def to_json(**opts)
|
|
140
|
+
add_notes opts[:note] do
|
|
141
|
+
namespace::Item.to_json(self)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def to_h(**opts)
|
|
146
|
+
add_notes opts[:note] do
|
|
147
|
+
namespace::Item.to_hash(self)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def to_bibtex
|
|
152
|
+
Converter::Bibtex.from_item(self).to_s
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def to_asciibib
|
|
156
|
+
Converter::Asciibib.from_item(self)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def to_rfcxml
|
|
160
|
+
Converter::BibXml.from_item(self).to_xml
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def deep_clone
|
|
164
|
+
namespace::Item.from_yaml namespace::Item.to_yaml(self)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def create_relation(**args)
|
|
168
|
+
if defined?(namespace::Relation)
|
|
169
|
+
namespace::Relation.new(**args)
|
|
170
|
+
else
|
|
171
|
+
Relation.new(**args)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def delete_title_part!
|
|
176
|
+
title&.delete_if { |t| t.type == "title-part" }
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def title_update_main # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
180
|
+
language&.each do |lang|
|
|
181
|
+
ttl = title.select { |t| t.type != "main" && t.language == lang }
|
|
182
|
+
next if ttl.empty?
|
|
183
|
+
|
|
184
|
+
tm_lang = ttl.map(&:content).join " - "
|
|
185
|
+
title.detect { |t| t.type == "main" && t.language == lang }&.content = tm_lang
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def ext_to_all_parts!
|
|
190
|
+
return unless ext
|
|
191
|
+
|
|
192
|
+
# some flavor modles have structuredidentifier as not an array
|
|
193
|
+
# so we need to make it an array use common method
|
|
194
|
+
array(ext.structuredidentifier).each(&:to_all_parts!)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def ext_remove_date
|
|
198
|
+
return unless ext
|
|
199
|
+
|
|
200
|
+
array(ext.structuredidentifier).each(&:remove_date!)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
private
|
|
204
|
+
|
|
205
|
+
def find_primary_docid
|
|
206
|
+
prim_docids = docidentifier.select(&:primary)
|
|
207
|
+
case prim_docids.size
|
|
208
|
+
when 0 then find_primary_or_english_docid(docidentifier)
|
|
209
|
+
when 1 then prim_docids.first
|
|
210
|
+
else find_primary_or_english_docid(prim_docids)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def find_primary_or_english_docid(docids) # rubocop:disable Metrics/CyclomaticComplexity
|
|
215
|
+
docids.reject(&:language).first ||
|
|
216
|
+
docids.find { |i| i.language&.casecmp("en")&.zero? } ||
|
|
217
|
+
docids.first
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def add_notes(notes)
|
|
221
|
+
self.note ||= []
|
|
222
|
+
array(notes).each { |nt| note << Bib::Note.new(**nt) }
|
|
223
|
+
result = yield
|
|
224
|
+
array(notes).each { note.pop }
|
|
225
|
+
result
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Address < Lutaml::Model::Serializable
|
|
4
|
+
attribute :street, :string, collection: true, initialize_empty: true
|
|
5
|
+
attribute :city, :string
|
|
6
|
+
attribute :state, :string
|
|
7
|
+
attribute :country, :string
|
|
8
|
+
attribute :postcode, :string
|
|
9
|
+
attribute :formatted_address, :string, raw: true
|
|
10
|
+
|
|
11
|
+
xml do
|
|
12
|
+
root "address"
|
|
13
|
+
map_element "street", to: :street
|
|
14
|
+
map_element "city", to: :city
|
|
15
|
+
map_element "state", to: :state
|
|
16
|
+
map_element "country", to: :country
|
|
17
|
+
map_element "postcode", to: :postcode
|
|
18
|
+
map_element "formattedAddress", to: :formatted_address
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Affiliation < Lutaml::Model::Serializable
|
|
4
|
+
attribute :name, LocalizedString
|
|
5
|
+
attribute :description, LocalizedMarkedUpString, collection: true, initialize_empty: true
|
|
6
|
+
attribute :organization, Organization
|
|
7
|
+
|
|
8
|
+
xml do
|
|
9
|
+
root "affiliation"
|
|
10
|
+
map_element "name", to: :name
|
|
11
|
+
map_element "description", to: :description
|
|
12
|
+
map_element "organization", to: :organization
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
module Contact
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.instance_eval do
|
|
6
|
+
attribute :address, Address, collection: true, initialize_empty: true
|
|
7
|
+
attribute :phone, Phone, collection: true, initialize_empty: true
|
|
8
|
+
attribute :email, :string, collection: true, initialize_empty: true
|
|
9
|
+
attribute :uri, Uri, collection: true, initialize_empty: true
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class ContributionInfo < Lutaml::Model::Serializable
|
|
4
|
+
choice(min: 1, max: 1) do
|
|
5
|
+
attribute :person, Person
|
|
6
|
+
attribute :organization, Organization
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
xml do
|
|
10
|
+
no_root
|
|
11
|
+
map_element "person", to: :person
|
|
12
|
+
map_element "organization", to: :organization
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Contributor < Lutaml::Model::Serializable
|
|
4
|
+
class Role < Lutaml::Model::Serializable
|
|
5
|
+
attribute :type, :string, values: %w[
|
|
6
|
+
author performer publisher editor adapter translator distributor reazer
|
|
7
|
+
owner authorizer enabler subject
|
|
8
|
+
]
|
|
9
|
+
attribute :description, LocalizedMarkedUpString, collection: true, initialize_empty: true
|
|
10
|
+
|
|
11
|
+
xml do
|
|
12
|
+
root "role"
|
|
13
|
+
map_attribute "type", to: :type
|
|
14
|
+
map_element "description", to: :description
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
attribute :role, Role, collection: true, initialize_empty: true
|
|
19
|
+
import_model_attributes ContributionInfo
|
|
20
|
+
|
|
21
|
+
xml do
|
|
22
|
+
root "contributor"
|
|
23
|
+
|
|
24
|
+
map_element "role", to: :role
|
|
25
|
+
import_model_mappings ContributionInfo
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Copyright < Lutaml::Model::Serializable
|
|
4
|
+
attribute :from, :string
|
|
5
|
+
attribute :to, :string
|
|
6
|
+
attribute :owner, ContributionInfo, collection: true, initialize_empty: true
|
|
7
|
+
attribute :scope, :string
|
|
8
|
+
|
|
9
|
+
xml do
|
|
10
|
+
root "copyright"
|
|
11
|
+
|
|
12
|
+
map_element "from", to: :from
|
|
13
|
+
map_element "to", to: :to
|
|
14
|
+
map_element "owner", to: :owner # , with: { from: :owner_from_xml, to: :owner_to_xml }
|
|
15
|
+
map_element "scope", to: :scope
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# def owner_from_xml(model, node)
|
|
19
|
+
# model.owner = ContributionInfo.from_xml node
|
|
20
|
+
# end
|
|
21
|
+
|
|
22
|
+
# def owner_to_xml(model, parent, _doc)
|
|
23
|
+
# model.owner.to_xml parent
|
|
24
|
+
# end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Date < Lutaml::Model::Serializable
|
|
4
|
+
attribute :type, :string, values: %w[
|
|
5
|
+
published accessed created implemented obsoleted confirmed updated
|
|
6
|
+
corrected issued transmitted copied unchanged circulated adapted
|
|
7
|
+
vote-started vote-ended announced stable-until
|
|
8
|
+
]
|
|
9
|
+
attribute :text, :string
|
|
10
|
+
choice(min: 1, max: 2) do
|
|
11
|
+
choice(min: 1, max: 2) do
|
|
12
|
+
attribute :from, StringDate
|
|
13
|
+
attribute :to, StringDate
|
|
14
|
+
end
|
|
15
|
+
# `on` is reserved word in YAML, so we use `at` to avoid remapping key-value formats
|
|
16
|
+
attribute :at, StringDate
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
xml do
|
|
20
|
+
root "date"
|
|
21
|
+
map_attribute "type", to: :type
|
|
22
|
+
map_attribute "text", to: :text
|
|
23
|
+
map_element "from", to: :from
|
|
24
|
+
map_element "to", to: :to
|
|
25
|
+
map_element "on", to: :at
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Depiction < Lutaml::Model::Serializable
|
|
4
|
+
attribute :scope, :string
|
|
5
|
+
attribute :type, :string
|
|
6
|
+
attribute :image, Image, collection: true, initialize_empty: true
|
|
7
|
+
|
|
8
|
+
xml do
|
|
9
|
+
root "depiction"
|
|
10
|
+
map_attribute "scope", to: :scope
|
|
11
|
+
map_attribute "type", to: :type
|
|
12
|
+
map_element "image", to: :image
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Docidentifier < LocalizedMarkedUpString
|
|
4
|
+
attribute :type, :string
|
|
5
|
+
attribute :scope, :string
|
|
6
|
+
attribute :primary, :boolean
|
|
7
|
+
|
|
8
|
+
xml do
|
|
9
|
+
root "docidentifier"
|
|
10
|
+
map_attribute "type", to: :type
|
|
11
|
+
map_attribute "scope", to: :scope
|
|
12
|
+
map_attribute "primary", to: :primary
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
key_value do
|
|
16
|
+
map "type", to: :type
|
|
17
|
+
map "scope", to: :scope
|
|
18
|
+
map "primary", to: :primary
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def remove_part!
|
|
22
|
+
raise NotImplementedError, "`remove_part!` method not implemented in #{self.class}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_all_parts!
|
|
26
|
+
raise NotImplementedError, "`to_all_parts!` method not implemented in #{self.class}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def remove_date!
|
|
30
|
+
raise NotImplementedError, "`remove_date!` method not implemented in #{self.class}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Doctype < Lutaml::Model::Serializable
|
|
4
|
+
attribute :abbreviation, :string
|
|
5
|
+
attribute :content, :string
|
|
6
|
+
|
|
7
|
+
xml do
|
|
8
|
+
root "doctype"
|
|
9
|
+
map_attribute "abbreviation", to: :abbreviation
|
|
10
|
+
map_content to: :content
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Edition < Lutaml::Model::Serializable
|
|
4
|
+
attribute :number, :string
|
|
5
|
+
attribute :content, :string
|
|
6
|
+
|
|
7
|
+
xml do
|
|
8
|
+
root "edition"
|
|
9
|
+
map_attribute "number", to: :number
|
|
10
|
+
map_content to: :content
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Ext < Lutaml::Model::Serializable
|
|
4
|
+
attribute :schema_version, :string, method: :get_schema_version
|
|
5
|
+
attribute :doctype, Doctype
|
|
6
|
+
attribute :subdoctype, :string
|
|
7
|
+
attribute :flavor, :string
|
|
8
|
+
attribute :ics, ICS, collection: true, initialize_empty: true
|
|
9
|
+
attribute :structuredidentifier, StructuredIdentifier, collection: true, initialize_empty: true
|
|
10
|
+
|
|
11
|
+
xml do
|
|
12
|
+
root "ext"
|
|
13
|
+
map_attribute "schema-version", to: :schema_version, render_default: true
|
|
14
|
+
map_element "doctype", to: :doctype
|
|
15
|
+
map_element "subdoctype", to: :subdoctype
|
|
16
|
+
map_element "flavor", to: :flavor
|
|
17
|
+
map_element "ics", to: :ics
|
|
18
|
+
map_element "structuredidentifier", to: :structuredidentifier
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
key_value do
|
|
22
|
+
map_element "schema_version", to: :schema_version, render_default: true
|
|
23
|
+
map_element "doctype", to: :doctype
|
|
24
|
+
map_element "subdoctype", to: :subdoctype
|
|
25
|
+
map_element "flavor", to: :flavor
|
|
26
|
+
map_element "ics", to: :ics
|
|
27
|
+
map_element "structuredidentifier", to: :structuredidentifier
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Base returns nil so direct use omits schema-version. Subclasses in
|
|
31
|
+
# downstream relaton gems override to return their own version.
|
|
32
|
+
def get_schema_version = nil
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Extent < Lutaml::Model::Serializable
|
|
4
|
+
choice(min: 1, max: 1) do
|
|
5
|
+
attribute :locality, Locality, collection: true, initialize_empty: true
|
|
6
|
+
attribute :locality_stack, LocalityStack, collection: true, initialize_empty: true
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
xml do
|
|
10
|
+
root "extent"
|
|
11
|
+
map_element "locality", to: :locality
|
|
12
|
+
map_element "localityStack", to: :locality_stack
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Bib
|
|
3
|
+
class Formattedref < LocalizedMarkedUpString
|
|
4
|
+
attribute :format, :string
|
|
5
|
+
|
|
6
|
+
xml do
|
|
7
|
+
root "formattedref"
|
|
8
|
+
map_attribute "format", to: :format
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
key_value do
|
|
12
|
+
map "format", to: :format
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Handle plain string input from YAML/JSON deserialization
|
|
16
|
+
def self.from_yaml(value)
|
|
17
|
+
return new(content: value) if value.is_a?(String)
|
|
18
|
+
|
|
19
|
+
super
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.from_json(value)
|
|
23
|
+
return new(content: value) if value.is_a?(String)
|
|
24
|
+
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Serialize as plain string when only content is present
|
|
29
|
+
def self.as(format, instance, options = {})
|
|
30
|
+
return instance.content if simple_content?(instance, format)
|
|
31
|
+
|
|
32
|
+
super
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.simple_content?(instance, format)
|
|
36
|
+
return false if format == :xml
|
|
37
|
+
|
|
38
|
+
instance.format.nil? && instance.language.nil? &&
|
|
39
|
+
instance.script.nil? && instance.locale.nil?
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|