| Class | Audio |
| In: |
app/models/audio.rb
|
| Parent: | ActiveRecord::Base |
Throughout the program the Audio class is referred to as "Sounds". Sounds would probably be a better name for this class as it is simpler word which encapsulates the concept fine. Originally it was thought that this class could be subdivided into more classes if needed including song, story and message. At the moment all of these things have similar needs so it has not been required. If this became important this would probably be best solved with Single Table Inheritance.
Currently the ferret search does not return media files based on contributors or subjects, but it should. This could be done by creating some extra methods to return the lists of all those involved, and then indexing these methods.
People are contributors to an Audio file if they helped to create it (recordists etc.). Subjects are animals, places etc. that are mentioned in the Audio. The person who narrates or sings could be seen as both a conributor and a subject, it is probably worth working what the best practice for such things is.
Using the file_column plugin the files are currently stored in the filesystem in public/audio/url/ according to the default settings. file_column is no longer supported and it would be worth thinking about moving to acts_as_attachment which is easier to maintain and customize.
schema.rb snippet:
create_table "audio", :force => true do |t|
t.column "url", :string, :null => false
t.column "format", :string
t.column "type", :string
t.column "description", :text
t.column "created_at", :datetime
t.column "updated_at", :datetime
t.column "recorded_on", :date
t.column "restriction", :string
t.column "original_format", :string
t.column "location_of_original", :string
t.column "catalogue_ref", :string
t.column "copyright_notice_id", :integer
end
equivalent to AudioSubject.create :audio => audio, :subject => subject, and probably could be replaced by this sort of call in all cases (this would be more RESTful and more directly CRUD).
# File app/models/audio.rb, line 64
64: def add_subject subject_to_add
65: unless subject_to_add.new_record?
66: subjects.each do |subject|
67: if subject == subject_to_add
68: return false
69: end
70: end
71: end
72: AudioSubject.create :audio => self, :subject => subject_to_add
73: end
Temporary solution to fact that media don‘t currently have a display name field.
# File app/models/audio.rb, line 83
83: def primary_names
84: if self.description.empty?
85: return 'Unnamed ' + self.class.to_s
86: else
87: text = self.description
88: result = text
89: if result.length > 80
90: truncated_text = text.slice(0, 77)
91: truncated_text.sub!(/\W+\w*$/, '')
92: result = truncated_text + '...'
93: end
94: return result
95: end
96: end
Destroys link between audio and subject, similarly to add_subject this could be replaced by a CRUD approach operating on AudioSubject directly.
# File app/models/audio.rb, line 77
77: def remove_subject subject_to_remove
78: subject = AudioSubject.find_by_video_id_and_subject_id_and_subject_type(self.id, subject_to_remove.id, subject_to_remove.class.to_s)
79: subject.destroy
80: end