Class: Vidibus::Fileinfo::Base
- Inherits:
-
Object
- Object
- Vidibus::Fileinfo::Base
- Defined in:
- lib/vidibus/fileinfo/base.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#processor ⇒ Object
Returns the value of attribute processor.
Instance Method Summary collapse
- #data ⇒ Object
- #format ⇒ Object
-
#initialize(path) ⇒ Base
constructor
A new instance of Base.
-
#mime_type(media_type = nil) ⇒ Object
(also: #content_type)
Return the mime type of the current instance.
Constructor Details
#initialize(path) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 |
# File 'lib/vidibus/fileinfo/base.rb', line 6 def initialize(path) @path = path check_file load_processor end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/vidibus/fileinfo/base.rb', line 4 def path @path end |
#processor ⇒ Object
Returns the value of attribute processor.
4 5 6 |
# File 'lib/vidibus/fileinfo/base.rb', line 4 def processor @processor end |
Instance Method Details
#data ⇒ Object
35 36 37 38 |
# File 'lib/vidibus/fileinfo/base.rb', line 35 def data raise PathError unless path @data ||= end |
#format ⇒ Object
12 13 14 |
# File 'lib/vidibus/fileinfo/base.rb', line 12 def format @format ||= Fileinfo.format(path) end |
#mime_type(media_type = nil) ⇒ Object Also known as: content_type
Return the mime type of the current instance. If a media_type is given, only a matching mime type will be returned.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vidibus/fileinfo/base.rb', line 19 def mime_type(media_type = nil) types = MIME::Types.type_for(path) return if types.empty? if media_type media_type = media_type.to_s media_types = types.select { |m| m.media_type == media_type } if media_types.length > 1 sub_types = media_types.select { |m| m.sub_type == format } media_types = sub_types if sub_types.any? end types = media_types if media_types.any? end types.first.content_type if types.any? end |