Class: Vidibus::Fileinfo::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vidibus/fileinfo/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/vidibus/fileinfo/base.rb', line 4

def path
  @path
end

#processorObject

Returns the value of attribute processor.



4
5
6
# File 'lib/vidibus/fileinfo/base.rb', line 4

def processor
  @processor
end

Instance Method Details

#dataObject

Raises:



35
36
37
38
# File 'lib/vidibus/fileinfo/base.rb', line 35

def data
  raise PathError unless path
  @data ||= 
end

#formatObject



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