Sha256: b30045aa5cc88f69dd6f912e15aee5245c733bf82e72db66c08d32efbae9471b

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

# -*- encoding: binary -*-

module VTools

  # job instance
  class Job
    attr_reader   :video, :id

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

    # execute job
    def execute
      # start hook
      Handler.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
      Handler.exec :job_finished, result, @video, @config.action
      result
    end

    # parse video options
    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
  end # Job
end # VTools

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vtools-0.1.1 lib/vtools/job.rb
vtools-0.1.0 lib/vtools/job.rb
vtools-0.0.3 lib/vtools/job.rb
vtools-0.0.2 lib/vtools/job.rb