Class: Ehbrs::Videos::ConvertJob

Inherits:
Object
  • Object
show all
Defined in:
lib/ehbrs/videos/convert_job.rb

Constant Summary collapse

FORMATS_TO_EXTENSIONS =
{
  'matroska' => '.mkv'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, profile) ⇒ ConvertJob

Returns a new instance of ConvertJob.



19
20
21
22
23
24
# File 'lib/ehbrs/videos/convert_job.rb', line 19

def initialize(input, profile)
  raise "Input file \"#{input}\" does not exist" unless ::File.exist?(input.to_s)

  @input = input
  @profile = profile
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



17
18
19
# File 'lib/ehbrs/videos/convert_job.rb', line 17

def input
  @input
end

#profileObject (readonly)

Returns the value of attribute profile.



17
18
19
# File 'lib/ehbrs/videos/convert_job.rb', line 17

def profile
  @profile
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
# File 'lib/ehbrs/videos/convert_job.rb', line 26

def run
  if ::File.exist?(converted)
    warn("Converted file already exist: \"#{converted}\"")
  else
    profile.run_callbacks(:convert) { convert }
    profile.run_callbacks(:swap) { swap }
  end
end

#targetObject



35
36
37
# File 'lib/ehbrs/videos/convert_job.rb', line 35

def target
  ::File.join(::File.dirname(input), "#{::File.basename(input, '.*')}#{target_extension}")
end