Class: MODSModel
- Inherits:
-
ASpaceExport::ExportModel
- Object
- ASpaceExport::ExportModel
- MODSModel
- Defined in:
- backend/app/exporters/models/mods.rb
Constant Summary collapse
- @@mods_note =
Struct.new(:tag, :type, :label, :content, :wrapping_tag)
Instance Attribute Summary collapse
-
#dates ⇒ Object
Returns the value of attribute dates.
-
#extent_notes ⇒ Object
Returns the value of attribute extent_notes.
-
#extents ⇒ Object
Returns the value of attribute extents.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#lang_materials ⇒ Object
Returns the value of attribute lang_materials.
-
#lang_notes ⇒ Object
Returns the value of attribute lang_notes.
-
#names ⇒ Object
Returns the value of attribute names.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#repository_note ⇒ Object
Returns the value of attribute repository_note.
-
#subjects ⇒ Object
Returns the value of attribute subjects.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type_of_resource ⇒ Object
Returns the value of attribute type_of_resource.
Class Method Summary collapse
-
.build_repo_note(repo_record) ⇒ Object
-
.from_archival_object(obj, tree) ⇒ Object
meaning, ‘archival object’ in the abstract.
-
.from_digital_object(obj, tree, opts = {}) ⇒ Object
-
.from_digital_object_component(obj, tree) ⇒ Object
-
.name_part_type_map ⇒ Object
-
.name_type_map ⇒ Object
-
.new_mods_note(*a) ⇒ Object
Instance Method Summary collapse
-
#each_related_item(children = nil, maxDepth = 20) ⇒ Object
-
#handle_agents(linked_agents) ⇒ Object
-
#handle_dates(dates) ⇒ Object
-
#handle_extents(extents, notes) ⇒ Object
-
#handle_extents_notes(notes) ⇒ Object
notes relating to extents are treated differently than other notes when the model is serialized.
-
#handle_id(digital_object_id) ⇒ Object
-
#handle_langmaterials(lang_materials) ⇒ Object
-
#handle_notes(notes) ⇒ Object
-
#handle_subjects(subjects) ⇒ Object
-
#initialize(tree) ⇒ MODSModel
constructor
A new instance of MODSModel.
-
#name_parts(name, type) ⇒ Object
-
#new_mods_note(*a) ⇒ Object
Methods inherited from ASpaceExport::ExportModel
#apply_map, inherited, model_for, model_for?
Constructor Details
#initialize(tree) ⇒ MODSModel
Returns a new instance of MODSModel.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'backend/app/exporters/models/mods.rb', line 51 def initialize(tree) @children = tree['children'] @extents = [] @notes = [] @extent_notes = [] @subjects = [] @names = [] @parts = [] @dates = [] @lang_materials = [] @lang_notes = [] end |
Instance Attribute Details
#dates ⇒ Object
Returns the value of attribute dates
18 19 20 |
# File 'backend/app/exporters/models/mods.rb', line 18 def dates @dates end |
#extent_notes ⇒ Object
Returns the value of attribute extent_notes
11 12 13 |
# File 'backend/app/exporters/models/mods.rb', line 11 def extent_notes @extent_notes end |
#extents ⇒ Object
Returns the value of attribute extents
9 10 11 |
# File 'backend/app/exporters/models/mods.rb', line 9 def extents @extents end |
#identifier ⇒ Object
Returns the value of attribute identifier
17 18 19 |
# File 'backend/app/exporters/models/mods.rb', line 17 def identifier @identifier end |
#lang_materials ⇒ Object
Returns the value of attribute lang_materials
7 8 9 |
# File 'backend/app/exporters/models/mods.rb', line 7 def lang_materials @lang_materials end |
#lang_notes ⇒ Object
Returns the value of attribute lang_notes
8 9 10 |
# File 'backend/app/exporters/models/mods.rb', line 8 def lang_notes @lang_notes end |
#names ⇒ Object
Returns the value of attribute names
13 14 15 |
# File 'backend/app/exporters/models/mods.rb', line 13 def names @names end |
#notes ⇒ Object
Returns the value of attribute notes
10 11 12 |
# File 'backend/app/exporters/models/mods.rb', line 10 def notes @notes end |
#parts ⇒ Object
Returns the value of attribute parts
15 16 17 |
# File 'backend/app/exporters/models/mods.rb', line 15 def parts @parts end |
#repository_note ⇒ Object
Returns the value of attribute repository_note
16 17 18 |
# File 'backend/app/exporters/models/mods.rb', line 16 def repository_note @repository_note end |
#subjects ⇒ Object
Returns the value of attribute subjects
12 13 14 |
# File 'backend/app/exporters/models/mods.rb', line 12 def subjects @subjects end |
#title ⇒ Object
Returns the value of attribute title
6 7 8 |
# File 'backend/app/exporters/models/mods.rb', line 6 def title @title end |
#type_of_resource ⇒ Object
Returns the value of attribute type_of_resource
14 15 16 |
# File 'backend/app/exporters/models/mods.rb', line 14 def type_of_resource @type_of_resource end |
Class Method Details
.build_repo_note(repo_record) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'backend/app/exporters/models/mods.rb', line 115 def self.build_repo_note(repo_record) agent = repo_record['agent_representation']['_resolved'] contacts = agent['agent_contacts'] contents = [repo_record['name']] if contacts.length > 0 contents += %w(address_1 address_2 address_3 city region post_code country).map {|part| contacts[0][part] }.compact end contents = contents.join(', ') if repo_record['url'] contents << " (#{repo_record['url']})" end new_mods_note('note', nil, "Digital object made available by", contents) end |
.from_archival_object(obj, tree) ⇒ Object
meaning, ‘archival object’ in the abstract
67 68 69 70 71 72 |
# File 'backend/app/exporters/models/mods.rb', line 67 def self.from_archival_object(obj, tree) mods = self.new(tree) mods.apply_map(obj, @archival_object_map) mods end |
.from_digital_object(obj, tree, opts = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'backend/app/exporters/models/mods.rb', line 75 def self.from_digital_object(obj, tree, opts = {}) mods = self.from_archival_object(obj, tree) if obj.respond_to? :digital_object_type unless obj.digital_object_type.nil? || obj.digital_object_type.empty? mods.type_of_resource = I18n.t("enumerations.digital_object_digital_object_type." + obj.digital_object_type) else mods.type_of_resource = nil end end mods.apply_map(obj, @digital_object_map, opts) mods.repository_note = build_repo_note(obj.repository['_resolved']) mods end |
.from_digital_object_component(obj, tree) ⇒ Object
94 95 96 97 98 |
# File 'backend/app/exporters/models/mods.rb', line 94 def self.from_digital_object_component(obj, tree) mods = self.from_archival_object(obj, tree) mods end |
.name_part_type_map ⇒ Object
105 106 107 |
# File 'backend/app/exporters/models/mods.rb', line 105 def self.name_part_type_map @name_part_type_map end |
.name_type_map ⇒ Object
101 102 103 |
# File 'backend/app/exporters/models/mods.rb', line 101 def self.name_type_map @name_type_map end |
.new_mods_note(*a) ⇒ Object
110 111 112 |
# File 'backend/app/exporters/models/mods.rb', line 110 def self.new_mods_note(*a) @@mods_note.new(*a) end |
Instance Method Details
#each_related_item(children = nil, maxDepth = 20) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'backend/app/exporters/models/mods.rb', line 300 def (children = nil, maxDepth = 20) return if maxDepth == 0 maxDepth = maxDepth - 1 children ||= @children return unless children children.each do |child| json = JSONModel(:digital_object_component).new(child) yield self.class.from_digital_object_component(json, child) if child['children'] (child['children'], maxDepth) do |item| yield item end end end end |
#handle_agents(linked_agents) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'backend/app/exporters/models/mods.rb', line 247 def handle_agents(linked_agents) linked_agents.each do |link| agent = link['_resolved'] role = link['role'] name_type = self.class.name_type_map[agent['jsonmodel_type']] # shift in granularity - role repeats for each name agent['names'].each do |name| self.names << { 'type' => name_type, 'role' => role, 'source' => name['source'], 'authority_id' => name['authority_id'], 'parts' => name_parts(name, agent['jsonmodel_type']), 'displayForm' => name['sort_name'] } end end end |
#handle_dates(dates) ⇒ Object
271 272 273 274 275 |
# File 'backend/app/exporters/models/mods.rb', line 271 def handle_dates(dates) dates.each do |date| self.dates.push date end end |
#handle_extents(extents, notes) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'backend/app/exporters/models/mods.rb', line 213 def handle_extents(extents, notes) extents.each do |ext| e = ext['number'] e << " #{ext['extent_type']}" self.extents << e # the extents hash may have data under keys 'physical_details' and 'dimensions'. # If found, we'll treat them as if they were notes of that type. if ext.has_key?('physical_details') && !ext['physical_details'].nil? extent_notes << new_mods_note('note', 'physical_description', "Physical Details", ext['physical_details']) end if ext.has_key?('dimensions') && !ext['dimensions'].nil? extent_notes << new_mods_note('note', 'dimensions', "Dimensions", ext['dimensions']) end end # process any physical_description and dimension notes that may be in the note list. handle_extents_notes(notes) end |
#handle_extents_notes(notes) ⇒ Object
notes relating to extents are treated differently than other notes when the model is serialized.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'backend/app/exporters/models/mods.rb', line 190 def handle_extents_notes(notes) notes.each do |note| next unless note['type'] == 'physdesc' || note['type'] == 'dimensions' next unless note['publish'] == true content = ASpaceExport::Utils.extract_note_text(note) mods_note = case note['type'] when 'physdesc' new_mods_note('note', 'physical_description', "Physical Details", content) when 'dimensions' new_mods_note('note', 'dimensions', "Dimensions", content) end self.extent_notes << mods_note end end |
#handle_id(digital_object_id) ⇒ Object
266 267 268 |
# File 'backend/app/exporters/models/mods.rb', line 266 def handle_id(digital_object_id) self.identifier = digital_object_id end |
#handle_langmaterials(lang_materials) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'backend/app/exporters/models/mods.rb', line 171 def handle_langmaterials(lang_materials) self.lang_materials = lang_materials.map {|l| l['language_and_script']}.compact language_notes = lang_materials.map {|l| l['notes']}.compact.reject {|e| e == [] }.flatten if !language_notes.empty? language_notes.each do |note| content = ASpaceExport::Utils.extract_note_text(note) mods_note = new_mods_note('note', 'language', note['label'], content) self.lang_notes << mods_note end end end |
#handle_notes(notes) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'backend/app/exporters/models/mods.rb', line 139 def handle_notes(notes) notes.each do |note| # physdesc and dimensions are treated separately from other notes next if note['type'] == 'physdesc' || note['type'] == 'dimensions' content = ASpaceExport::Utils.extract_note_text(note) mods_note = case note['type'] when 'accessrestrict' new_mods_note('accessCondition', 'restrictionOnAccess', note['label'], content) when 'userestrict' new_mods_note('accessCondition', 'useAndReproduction', note['label'], content) when 'legalstatus' new_mods_note('accessCondition', note['type'], note['label'], content) else new_mods_note('note', note['type'], note['label'], content) end self.notes << mods_note end end |
#handle_subjects(subjects) ⇒ Object
236 237 238 239 240 241 242 243 244 |
# File 'backend/app/exporters/models/mods.rb', line 236 def handle_subjects(subjects) subjects.map {|s| s['_resolved'] }.each do |subject| self.subjects << { 'term' => subject['terms'].map {|t| t['term']}, 'source' => subject['source'], 'term_type' => subject['terms'].map {|t| t['term_type']} } end end |
#name_parts(name, type) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'backend/app/exporters/models/mods.rb', line 278 def name_parts(name, type) fields = case type when 'agent_person' ["primary_name", "title", "prefix", "rest_of_name", "suffix", "fuller_form", "number"] when 'agent_family' ["family_name", "prefix"] when 'agent_software' ["software_name", "version", "manufacturer"] when 'agent_corporate_entity' ["primary_name", "subordinate_name_1", "subordinate_name_2", "number"] end parts = [] fields.each do |field| part = {} part['type'] = self.class.name_part_type_map[field] part.delete('type') if part['type'].nil? part['content'] = name[field] unless name[field].nil? parts << part unless part.empty? end parts end |
#new_mods_note(*a) ⇒ Object
134 135 136 |
# File 'backend/app/exporters/models/mods.rb', line 134 def new_mods_note(*a) self.class.new_mods_note(*a) end |