Class: Titlekit::Job

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJob

Starts a new job.

A job requires at least one file you Have and one file you Want in order to be runable. Use #have and #want to add and obtain specification interfaces for the job.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/titlekit/job.rb', line 30

def initialize
  @haves = []
  @wants = []
  @report = []

  require 'rchardet19'

  begin
    if Gem::Specification.find_by_name('charlock_holmes')
      require 'charlock_holmes'
    end
  rescue Gem::LoadError
  end
end

Instance Attribute Details

#havesArray<Have> (readonly)

Returns everything you Have

Returns:



10
11
12
# File 'lib/titlekit/job.rb', line 10

def haves
  @haves
end

#reportArray<String> (readonly)

Returns the job report, which documents the direct cause of failures and any other unusual events that occur on the job. (regardless if it failed or succeeded)

Returns:

  • (Array<String>)

    All reported messages



22
23
24
# File 'lib/titlekit/job.rb', line 22

def report
  @report
end

#wantsArray<Want> (readonly)

Returns everything you Want

Returns:



15
16
17
# File 'lib/titlekit/job.rb', line 15

def wants
  @wants
end

Instance Method Details

#have(*_args, template: nil, &block) ⇒ Have

Adds a new Have specification to your job.

Examples:

Using a block without a variable (careful: the scope changes!)

job.have do
  encoding('utf-8')
  file('path/to/my/input.srt')
  fps(25)
end

Using a block and providing a variable

job.have do |have|
  have.encoding('utf-8')
  have.file('path/to/my/input.srt')
  have.fps(25)
end

Catching the reference and assigning things at any later point

have = job.have
have.encoding('utf-8')
have.file('path/to/my/input.srt')
have.fps(25)

Cloning a previous specification and extending on it

have2 = job.have(template: have1)
have2.encoding('ISO-8859-1')
have2.file('path/to/my/input2.srt')

Parameters:

  • template (Have) (defaults to: nil)

    optionally you can specify another Have as a template, from which all properties but the file path are cloned

Returns:

  • (Have)

    a reference to the newly assigned Have



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/titlekit/job.rb', line 99

def have(*_args, template: nil, &block)
  specification = Have.new

  if template
    specification.fps = template.fps.clone
    specification.references = template.references.clone
  end

  if block
    if block.arity < 1
      specification.instance_eval(&block)
    else
      block[specification]
    end
  end

  @haves << specification

  specification
end

#runBoolean

Runs the job.

Returns:

  • (Boolean)

    true if the job succeeds, false if it fails. #report provides information in case of failure.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/titlekit/job.rb', line 49

def run
  @wants.each do |want|
    @haves.each do |have|
      import(have)
      retime(have, want)
      cull(have)
      group(have)

      want.subtitles += have.subtitles.clone
    end

    polish(want)
    export(want)
  end

  return true
rescue AbortJob
  return false
end

#want(*args, template: nil, &block) ⇒ Want

Adds a new Want specification to your job.

Examples:

Using a block without a variable (careful: the scope changes!)

job.want do
  encoding('utf-8')
  file('path/to/my/output.srt')
  fps(23.976)
end

Using a block and providing a variable

job.want do |want|
  want.encoding('utf-8')
  want.file('path/to/my/output.srt')
  want.fps((23.976)
end

Catching the reference and assigning things at any later point

want = job.want
want.encoding('utf-8')
want.file('path/to/my/output.srt')
want.fps((23.976)

Cloning a previous specification and extending on it

want2 = job.want(template: want1)
want2.encoding('ISO-8859-1')
want2.file('path/to/my/output.ass')

Parameters:

  • template (Want) (defaults to: nil)

    optionally you can specify another Want as a template, from which all properties but the file path are cloned

Returns:

  • (Want)

    a reference to the newly assigned Want



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/titlekit/job.rb', line 150

def want(*args, template: nil, &block)
  specification = Want.new

  if template
    specification.fps = template.fps.clone
    specification.references = template.references.clone
  end

  if block
    if block.arity < 1
      specification.instance_eval(&block)
    else
      block[specification]
    end
  end

  @wants << specification

  specification
end