Class: VTools::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/vtools/job.rb

Overview

job instance

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Job

Returns a new instance of Job.



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

def initialize config
  @id = self.object_id.to_i
  @config = validate config
  @video  = Video.new @config.file
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/vtools/job.rb', line 7

def id
  @id
end

#videoObject (readonly)

Returns the value of attribute video.



7
8
9
# File 'lib/vtools/job.rb', line 7

def video
  @video
end

Instance Method Details

#executeObject

execute job



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vtools/job.rb', line 16

def execute
  # start hook
  Hook.exec :job_started, @video, @config.action

  result = @video.get_info # we always get info

  case @config.action
  when /^convert$/i
    result = @video.convert @config.setup # will return video
  when /^thumbs$/i
    result = @video.create_thumbs @config.setup # will return thumbs array
  end

  # final hook
  Hook.exec :job_finished, result, @video, @config.action
  result
end

#validate(options) ⇒ Object

parse video options



35
36
37
38
39
40
41
42
43
44
# File 'lib/vtools/job.rb', line 35

def validate options
  unless options.action =~ /^convert|thumbs|info$/ && options.file && !options.file.empty?
    raise ConfigError, "Invalid action (config: #{options.marshal_dump})"
  else
    return options if options.action =~ /^info$/
    # empty set error
    raise ConfigError, "Configuration is empty" if !options.setup || options.setup.empty?
  end
  options
end