Class: TranscodingMachine::MediaFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/transcoding_machine/media_format.rb

Direct Known Subclasses

AudioFormat, VideoFormat

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ MediaFormat

Returns a new instance of MediaFormat.



8
9
10
11
12
13
14
15
16
# File 'lib/transcoding_machine/media_format.rb', line 8

def initialize(args)
  @fixed_criteria = []
  @priority = args[:priority]
  @id = args[:id]
  @suffix = args[:suffix]
  @mime_type = args[:mime_type]
  @command = args[:command]
  @criteria = args[:criteria] || []
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/transcoding_machine/media_format.rb', line 6

def command
  @command
end

#criteriaObject (readonly)

Returns the value of attribute criteria.



6
7
8
# File 'lib/transcoding_machine/media_format.rb', line 6

def criteria
  @criteria
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/transcoding_machine/media_format.rb', line 6

def id
  @id
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



6
7
8
# File 'lib/transcoding_machine/media_format.rb', line 6

def mime_type
  @mime_type
end

#priorityObject (readonly)

Returns the value of attribute priority.



6
7
8
# File 'lib/transcoding_machine/media_format.rb', line 6

def priority
  @priority
end

#suffixObject (readonly)

Returns the value of attribute suffix.



6
7
8
# File 'lib/transcoding_machine/media_format.rb', line 6

def suffix
  @suffix
end

Class Method Details

.best_match_for(media_file_attributes, sorted_formats) ⇒ Object



43
44
45
# File 'lib/transcoding_machine/media_format.rb', line 43

def self.best_match_for(media_file_attributes, sorted_formats)
  sorted_formats.first {|f| f.can_transcode?(media_file_attributes)}
end

.type_cast_attribute_value(key, value) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/transcoding_machine/media_format.rb', line 26

def self.type_cast_attribute_value(key, value)
  case Server::MediaFileAttributes::FIELD_TYPES[key]
  when :boolean
    (value.to_s.downcase == 'true' || value.to_s == '1')
  when :string
    value.to_s
  when :integer
    value.to_i
  when :float
    value.to_f
  when :codec
    value.to_sym
  else
    raise "unknown key (#{key}) for MediaFormat attribute"
  end
end

Instance Method Details

#can_transcode?(media_file_attributes) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/transcoding_machine/media_format.rb', line 22

def can_transcode?(media_file_attributes)
  
end

#matches(media_file_attributes) ⇒ Object



18
19
20
# File 'lib/transcoding_machine/media_format.rb', line 18

def matches(media_file_attributes)
  (@fixed_criteria + @criteria).all? { |c| c.matches(media_file_attributes) }
end