Class: VTools::ConvertOptions

Inherits:
Hash
  • Object
show all
Includes:
SharedMethods
Defined in:
lib/vtools/convert_options.rb

Overview

options for the video converter

Instance Method Summary collapse

Methods included from SharedMethods

included

Methods included from SharedMethods::Common

#config, #fix_encoding, #generate_path, #hash_to_obj, #json_to_obj, #keys_to_sym, #log, #logger=, #network_call, #parse_json, #path_generator

Constructor Details

#initialize(options = {}) ⇒ ConvertOptions

Returns a new instance of ConvertOptions.



9
10
11
12
# File 'lib/vtools/convert_options.rb', line 9

def initialize options = {}
  @ignore = [:width, :height, :resolution, :extension, :preserve_aspect, :duration, :postfix]
  parse! options
end

Instance Method Details

#[]=(key, value) ⇒ Object

set value method backward compatibility for width height & resolution



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vtools/convert_options.rb', line 16

def []= (key, value)
  ignore = @ignore[0..2] << :s

  case
  # width & height
  when ignore.first(2).include?(key)
    ignore.last(2).each { |index| delete(index) }
    data = { key => value }
  # resolution
  when ignore.last(2).include?(key)
    ignore.each { |index| delete(index) }
    width, height = value.split("x")
    data = { :width => width.to_i, :height => height.to_i, :resolution => value, :s => value}
  # duration
  when [:duration, :t].include?(key)
    data = { :duration => value, :t => value }
  else
    return super
  end

  merge! data
  return value
end

#to_sObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vtools/convert_options.rb', line 40

def to_s

  params = collect do |key, value|
    "-#{key} #{value}" unless @ignore.include?(key)
  end.compact

  # put the preset parameters last
  params  = params.reject { |p| p =~ /[avfs]pre/ } + params.select { |p| p =~ /[avfs]pre/ }

  params.join " "
end