Class Video
In: app/models/video.rb
Parent: ActiveRecord::Base

The Video class is functionally very similar to the Audio class.

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 media file if they helped to create it (recordists etc.). Subjects are animals, places etc. that are mentioned in the Video. The person who narrates a video 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 "videos", :force => true do |t|
    t.column "url",                  :string,   :null => false
    t.column "format",               :string
    t.column "width",                :integer
    t.column "height",               :integer
    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

Methods

Public Instance methods

Use this to add a subject to the video, since subjects is polymorphic this could be a Person, Place, Animal or any other entity in the database.

[Source]

    # File app/models/video.rb, line 59
59:   def add_subject subject_to_add
60:       unless subject_to_add.new_record?
61:           subjects.each do |subject| 
62:               if subject == subject_to_add 
63:                   return false
64:               end
65:           end
66:       end
67:       VideoSubject.create :video => self, :subject => subject_to_add
68:   end

Temporary solution to fact that media don‘t currently have a display name field.

[Source]

    # File app/models/video.rb, line 76
76:   def primary_names
77:     if self.description.empty?
78:       return 'Unnamed ' + self.class.to_s
79:     else
80:       text = self.description
81:       result = text
82:       if result.length > 80
83:         truncated_text = text.slice(0, 77)
84:         truncated_text.sub!(/\W+\w*$/, '')
85:         result = truncated_text + '...'
86:       end
87:       return result
88:     end
89:   end

[Source]

    # File app/models/video.rb, line 70
70:   def remove_subject subject_to_remove
71:     subject = VideoSubject.find_by_video_id_and_subject_id_and_subject_type(self.id, subject_to_remove.id, subject_to_remove.class.to_s)
72:     subject.destroy
73:   end

Returns all subjects of the video.

[Source]

    # File app/models/video.rb, line 54
54:   def subjects
55:         video_subjects.collect {|video_subject| video_subject.subject}
56:   end

[Validate]