Class: MODSSerializer
Constant Summary
Constants included
from JSONModel
JSONModel::REFERENCE_KEY_REGEX
Instance Method Summary
collapse
Methods included from JSONModel
JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, check_valid_refs, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_publish_flags!, set_repository, strict_mode, strict_mode?, validate_schema, with_repository
inherited, serializer_for, serializer_for?, with_namespace
Instance Method Details
#serialize(mods, opts = {}) ⇒ Object
6
7
8
9
10
11
12
|
# File 'backend/app/exporters/serializers/mods.rb', line 6
def serialize(mods, opts = {})
builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
serialize_mods(mods, xml)
end
builder.to_xml
end
|
#serialize_mods(mods, xml) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'backend/app/exporters/serializers/mods.rb', line 14
def serialize_mods(mods, xml)
root_args = {'version' => '3.4'}
root_args['xmlns'] = 'http://www.loc.gov/mods/v3'
xml.mods(root_args) {
serialize_mods_inner(mods, xml)
}
end
|
#serialize_mods_inner(mods, xml) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'backend/app/exporters/serializers/mods.rb', line 23
def serialize_mods_inner(mods, xml)
xml.titleInfo {
xml.title mods.title
}
xml.identifier mods.identifier
xml.typeOfResource mods.type_of_resource
unless mods.lang_materials.nil?
mods.lang_materials.each do |language|
xml.language {
xml.languageTerm(:type => 'text', :authority => 'iso639-2b') {
xml.text I18n.t("enumerations.language_iso639_2." + language['language'])
}
xml.languageTerm(:type => 'code', :authority => 'iso639-2b') {
xml.text language['language']
}
unless language['script'].nil?
xml.scriptTerm(:type => 'text', :authority => 'iso15924') {
xml.text I18n.t("enumerations.script_iso15924." + language['script'])
}
xml.scriptTerm(:type => 'code', :authority => 'iso15924') {
xml.text language['script']
}
end
}
end
mods.lang_notes.each do |note|
serialize_note(note, xml)
end
end
mods.dates.each do |date|
handle_date(xml, date)
end
xml.physicalDescription {
mods.extents.each do |extent|
xml.extent extent
end
mods.extent_notes.each do |note|
serialize_note(note, xml)
end
}
mods.notes.each do |note|
if note.wrapping_tag
xml.send(note.wrapping_tag) {
serialize_note(note, xml)
}
else
serialize_note(note, xml)
end
end
if (repo_note = mods.repository_note)
xml.note(:displayLabel => repo_note.label) {
xml.text repo_note.content
}
end
mods.subjects.each do |subject|
xml.subject(:authority => subject['source']) {
term = subject['term'].join(" -- ")
case subject['term_type'].first
when 'geographic', 'cultural_context'
xml.geographic term
when 'temporal'
xml.temporal term
when 'uniform_title'
xml.titleInfo term
when 'genre_form', 'style_period', 'technique', 'function'
xml.genre term
when 'occupation'
xml.occupation term
else
xml.topic term
end
}
end
mods.names.each do |name|
case name['role']
when 'subject'
xml.subject {
serialize_name(name, xml)
}
else
serialize_name(name, xml)
end
end
mods.parts.each do |part|
xml.part(:ID => part['id']) {
xml.detail {
xml.title part['title']
}
}
end
mods.each_related_item do |item|
xml.relatedItem(:type => 'constituent') {
serialize_mods_inner(item, xml)
}
end
end
|
#serialize_name(name, xml) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'backend/app/exporters/serializers/mods.rb', line 141
def serialize_name(name, xml)
atts = {:type => name['type']}
atts[:authority] = name['source'] if name['source']
atts["valueURI"] = name['authority_id'] if name['authority_id']
xml.name(atts) {
name['parts'].each do |part|
if part['type']
xml.namePart(:type => part['type']) {
xml.text part['content']
}
else
xml.namePart part['content']
end
end
xml.role {
xml.roleTerm(:type => 'text', :authority => 'marcrelator') {
xml.text name['role']
}
}
}
end
|
#serialize_note(note, xml) ⇒ Object
164
165
166
167
168
169
170
171
172
|
# File 'backend/app/exporters/serializers/mods.rb', line 164
def serialize_note(note, xml)
atts = {}
atts[:type] = note.type if note.type
atts[:displayLabel] = note.label if note.label
xml.send(note.tag, atts) {
xml.text note.content
}
end
|