def create file, content_type = nil
if file.is_a? File
cntnt = file.read
ctype = content_type || file_type(file.path)
fname = file.path
else
cntnt = IO.read(file)
ctype = content_type || file_type(file)
fname = file
end
raise UnknownContentError unless ctype
media_obj =
case ctype.match(/^(\w+)\//)[1]
when 'application'; ApplicationMedia.new(cntnt, ctype)
when 'audio' ; AudioMedia.new(cntnt, ctype)
when 'image' ; ImageMedia.new(cntnt, ctype)
when 'text' ; TextMedia.new(cntnt, ctype)
when 'video' ; VideoMedia.new(cntnt, ctype)
end
class << media_obj; attr_accessor :path end
media_obj.path = fname
media_obj
end