Class: TranscodingMachine::MediaFormatCriterium

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

Constant Summary collapse

TYPE_OPERATORS =
{
  :boolean => [:equals, :not_equals],
  :string  => [:equals, :not_equals],
  :integer => [:equals, :not_equals, :lt, :lte, :gt, :gte],
  :float   => [:equals, :not_equals, :lt, :lte, :gt, :gte],
  :codec   => [:equals, :not_equals]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ MediaFormatCriterium

Returns a new instance of MediaFormatCriterium.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/transcoding_machine/media_format_criterium.rb', line 15

def initialize(args)
  @key = args[:key].to_sym
  
  @operator = (args[:operator] || :equals).to_sym
  
  @value = MediaFormat.type_cast_attribute_value(@key, args[:value])
  
  unless MediaFormatCriterium::TYPE_OPERATORS[value_type].include?(@operator)
    raise "invalid operator (#{@operator}) for MediaFormatCriterium with key #{@key}"
  end
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



14
15
16
# File 'lib/transcoding_machine/media_format_criterium.rb', line 14

def key
  @key
end

#operatorObject (readonly)

Returns the value of attribute operator.



14
15
16
# File 'lib/transcoding_machine/media_format_criterium.rb', line 14

def operator
  @operator
end

#valueObject (readonly)

Returns the value of attribute value.



14
15
16
# File 'lib/transcoding_machine/media_format_criterium.rb', line 14

def value
  @value
end

Instance Method Details

#matches(media_file_attributes) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/transcoding_machine/media_format_criterium.rb', line 31

def matches(media_file_attributes)
  attr_value = MediaFormat.type_cast_attribute_value(@key, media_file_attributes[@key])
  case @operator
  when :equals
    attr_value == @value
  when :lt
    attr_value < @value
  when :gt
    attr_value > @value
  when :lte
    attr_value <= @value
  when :gte
    attr_value >= @value
  when :not_equals
    attr_value != @value
  end
end

#value_typeObject



27
28
29
# File 'lib/transcoding_machine/media_format_criterium.rb', line 27

def value_type
  Server::MediaFileAttributes::FIELD_TYPES[@key]
end