class Episode < ActiveRecord::Base attr_protected :permalink belongs_to :program validates_presence_of :title validates_uniqueness_of :title validates_associated :program # TODO This requires that a value be entered for each of these, # which is not always the case. # # validates_numericality_of :mp3_length # validates_numericality_of :mp4_length def before_create @attributes['permalink'] = @attributes['title'].downcase.gsub(/\s+/, '-').gsub(/[^a-zA-Z0-9_\-]+/, '') @attributes['published_at'] = Time.now.utc if @attributes['published_at'].blank? end def before_save if has_transcript && transcript_published_at.blank? @attributes['transcript_published_at'] = Time.now.utc end end ## # Makes urls search-engine friendly. # # /programs/1/episodes/bart_simpson # def to_param permalink end # TODO # Resolve relative paths for mp3_url: /..., a..., http://... # # TODO # Set transcript_published_at if has_transcript was updated end