Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/vov 1419 #45

Merged
merged 2 commits into from
Apr 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions app/models/media_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,22 @@ def update_attribute_in_metadata(attribute, value = [], attributes = [])
end

def set_media_types!
resource_type_names = {
'audio' => 'sound recording',
'video' => 'moving image'
}
mime_types = parts.collect { |mf|
mf.file_location.nil? ? nil : Rack::Mime.mime_type(File.extname(mf.file_location))
}.compact.uniq
resource_types = mime_types.collect { |mime| resource_type_names[mime.split('/').first] }.compact.uniq

resource_type_to_formatted_text_map = {'Moving image' => 'Moving image', 'Sound' => 'Sound recording'}
resource_types = self.parts.collect{|master_file| resource_type_to_formatted_text_map[master_file.file_format] }.uniq

mime_types = nil if mime_types.empty?
resource_types = nil if resource_types.empty?

descMetadata.ensure_physical_description_exists!
descMetadata.ensure_root_term_exists!(:physical_description)
descMetadata.ensure_root_term_exists!(:resource_type)

descMetadata.find_by_terms(:physical_description, :internet_media_type).remove
descMetadata.find_by_terms(:resource_type).remove

descMetadata.update_values([:physical_description, :internet_media_type] => mime_types, [:resource_type] => resource_types)
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/mods_behaviors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def update_change_date!(t=Time.now.iso8601)
self.record_change_date = t
end

def ensure_physical_description_exists!
if find_by_terms(:physical_description).empty?
ng_xml.root.add_child('<physicalDescription/>')
def ensure_root_term_exists!(term)
if find_by_terms(term).empty?
ng_xml.root.add_child("<#{term.to_s.camelcase(first_letter = :lower)}/>")
end
end

Expand Down