Class: METSModel
- Inherits:
-
ASpaceExport::ExportModel
- Object
- ASpaceExport::ExportModel
- METSModel
- Defined in:
- backend/app/exporters/models/mets.rb
Constant Summary collapse
- @@logical_div =
Struct.new(:label, :dmdid, :file_versions, :children) do
Instance Attribute Summary collapse
-
#dc_model ⇒ Object
Returns the value of attribute dc_model.
-
#dmd_id ⇒ Object
Returns the value of attribute dmd_id.
-
#extents ⇒ Object
Returns the value of attribute extents.
-
#header_agent_name ⇒ Object
Returns the value of attribute header_agent_name.
-
#header_agent_notes ⇒ Object
Returns the value of attribute header_agent_notes.
-
#header_agent_role ⇒ Object
Returns the value of attribute header_agent_role.
-
#header_agent_type ⇒ Object
Returns the value of attribute header_agent_type.
-
#mods_model ⇒ Object
Returns the value of attribute mods_model.
-
#names ⇒ Object
Returns the value of attribute names.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#subjects ⇒ Object
Returns the value of attribute subjects.
-
#type_of_resource ⇒ Object
Returns the value of attribute type_of_resource.
-
#wrapped_dmd ⇒ Object
Returns the value of attribute wrapped_dmd.
Class Method Summary collapse
-
.from_archival_object(obj, tree) ⇒ Object
-
.from_aspace_object(obj, tree) ⇒ Object
-
.from_digital_object(obj, tree) ⇒ Object
-
.get_file_group(*args) ⇒ Object
-
.name_part_type_map ⇒ Object
-
.name_type_map ⇒ Object
Instance Method Summary collapse
-
#add_agent_note(val) ⇒ Object
-
#children ⇒ Object
-
#dmd_wrap(mdtype, callback, data) ⇒ Object
-
#extract_file_versions(children) ⇒ Object
-
#initialize(obj, tree) ⇒ METSModel
constructor
A new instance of METSModel.
-
#method_missing(meth) ⇒ Object
-
#root_logical_div ⇒ Object
-
#root_physical_div ⇒ Object
-
#with_file_groups ⇒ Object
Methods inherited from ASpaceExport::ExportModel
#apply_map, inherited, model_for, model_for?
Constructor Details
#initialize(obj, tree) ⇒ METSModel
Returns a new instance of METSModel.
110 111 112 113 114 115 116 117 118 119 |
# File 'backend/app/exporters/models/mets.rb', line 110 def initialize(obj, tree) @json = obj @tree = tree @wrapped_dmd = [] @extents = [] @notes = [] @subjects = [] @names = [] @parts = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object
183 184 185 186 187 188 189 |
# File 'backend/app/exporters/models/mets.rb', line 183 def method_missing(meth) if @json.respond_to?(meth) @json.send(meth) else nil end end |
Instance Attribute Details
#dc_model ⇒ Object
Returns the value of attribute dc_model
12 13 14 |
# File 'backend/app/exporters/models/mets.rb', line 12 def dc_model @dc_model end |
#dmd_id ⇒ Object
Returns the value of attribute dmd_id
21 22 23 |
# File 'backend/app/exporters/models/mets.rb', line 21 def dmd_id @dmd_id end |
#extents ⇒ Object
Returns the value of attribute extents
15 16 17 |
# File 'backend/app/exporters/models/mets.rb', line 15 def extents @extents end |
#header_agent_name ⇒ Object
Returns the value of attribute header_agent_name
6 7 8 |
# File 'backend/app/exporters/models/mets.rb', line 6 def header_agent_name @header_agent_name end |
#header_agent_notes ⇒ Object
Returns the value of attribute header_agent_notes
7 8 9 |
# File 'backend/app/exporters/models/mets.rb', line 7 def header_agent_notes @header_agent_notes end |
#header_agent_role ⇒ Object
Returns the value of attribute header_agent_role
8 9 10 |
# File 'backend/app/exporters/models/mets.rb', line 8 def header_agent_role @header_agent_role end |
#header_agent_type ⇒ Object
Returns the value of attribute header_agent_type
9 10 11 |
# File 'backend/app/exporters/models/mets.rb', line 9 def header_agent_type @header_agent_type end |
#mods_model ⇒ Object
Returns the value of attribute mods_model
11 12 13 |
# File 'backend/app/exporters/models/mets.rb', line 11 def mods_model @mods_model end |
#names ⇒ Object
Returns the value of attribute names
18 19 20 |
# File 'backend/app/exporters/models/mets.rb', line 18 def names @names end |
#notes ⇒ Object
Returns the value of attribute notes
16 17 18 |
# File 'backend/app/exporters/models/mets.rb', line 16 def notes @notes end |
#parts ⇒ Object
Returns the value of attribute parts
20 21 22 |
# File 'backend/app/exporters/models/mets.rb', line 20 def parts @parts end |
#subjects ⇒ Object
Returns the value of attribute subjects
17 18 19 |
# File 'backend/app/exporters/models/mets.rb', line 17 def subjects @subjects end |
#type_of_resource ⇒ Object
Returns the value of attribute type_of_resource
19 20 21 |
# File 'backend/app/exporters/models/mets.rb', line 19 def type_of_resource @type_of_resource end |
#wrapped_dmd ⇒ Object
Returns the value of attribute wrapped_dmd
13 14 15 |
# File 'backend/app/exporters/models/mets.rb', line 13 def wrapped_dmd @wrapped_dmd end |
Class Method Details
.from_archival_object(obj, tree) ⇒ Object
143 144 145 146 147 |
# File 'backend/app/exporters/models/mets.rb', line 143 def self.from_archival_object(obj, tree) mets = self.from_aspace_object(obj, tree) mets.apply_map(obj, @archival_object_map) mets end |
.from_aspace_object(obj, tree) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'backend/app/exporters/models/mets.rb', line 127 def self.from_aspace_object(obj, tree) mets = self.new(obj, tree) if obj.respond_to?(:repo_id) repo_id = RequestContext.get(:repo_id) mets.apply_map(Repository.get_or_die(repo_id), @repository_map) mets.header_agent_role = "CREATOR" mets.header_agent_type = "ORGANIZATION" end mets.add_agent_note("Produced by ArchivesSpace") mets end |
.from_digital_object(obj, tree) ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'backend/app/exporters/models/mets.rb', line 150 def self.from_digital_object(obj, tree) mets = self.from_archival_object(obj, tree) mets.type_of_resource = obj.digital_object_type mets.apply_map(obj, @digital_object_map) # wrapped DMD mets.mods_model = ASpaceExport.model(:mods).from_digital_object(obj, :ignore => [:tree]) mets.dc_model = ASpaceExport.model(:dc).from_digital_object(obj) mets end |
.get_file_group(*args) ⇒ Object
122 123 124 |
# File 'backend/app/exporters/models/mets.rb', line 122 def self.get_file_group(*args) @file_group.new(*args) end |
.name_part_type_map ⇒ Object
167 168 169 |
# File 'backend/app/exporters/models/mets.rb', line 167 def self.name_part_type_map @name_part_type_map end |
.name_type_map ⇒ Object
162 163 164 |
# File 'backend/app/exporters/models/mets.rb', line 162 def self.name_type_map @name_type_map end |
Instance Method Details
#add_agent_note(val) ⇒ Object
172 173 174 175 |
# File 'backend/app/exporters/models/mets.rb', line 172 def add_agent_note(val) @header_agent_notes ||= [] @header_agent_notes << val end |
#children ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'backend/app/exporters/models/mets.rb', line 192 def children return nil unless @tree['children'] ao_class = self.class.instance_variable_get(:@doc) children = @tree['children'].map { |subtree| ao_class.new(subtree) } children end |
#dmd_wrap(mdtype, callback, data) ⇒ Object
178 179 180 |
# File 'backend/app/exporters/models/mets.rb', line 178 def dmd_wrap(mdtype, callback, data) self.wrapped_dmd << {'type' => mdtype, 'callback' => callback, 'data' => data} end |
#extract_file_versions(children) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'backend/app/exporters/models/mets.rb', line 278 def extract_file_versions(children) file_versions = [] children.each do |child| if child['file_versions'] file_versions += child['file_versions'] end if child['children'] file_versions += extract_file_versions(child['children']) end end file_versions end |
#root_logical_div ⇒ Object
260 261 262 263 264 265 266 |
# File 'backend/app/exporters/models/mets.rb', line 260 def root_logical_div @@logical_div.init @@logical_div.new(@json.title, @json.id, @json.file_versions, @tree['children']) end |
#root_physical_div ⇒ Object
269 270 271 272 273 274 275 |
# File 'backend/app/exporters/models/mets.rb', line 269 def root_physical_div @@logical_div.init @@logical_div.new(@json.title, @json.id, @json.file_versions, @tree['children']) end |
#with_file_groups ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'backend/app/exporters/models/mets.rb', line 203 def with_file_groups file_versions = @json.file_versions file_versions.each do |fv| fv['digital_object_id'] = @json.id end file_versions += extract_file_versions(@tree['children']) file_versions.compact! while file_versions.length > 0 use_statement = file_versions[0]['use_statement'] use_group = file_versions.select {|fv| fv['use_statement'] == use_statement } yield self.class.get_file_group(use_statement, use_group) file_versions.reject! {|fv| fv['use_statement'] == use_statement } end end |