Class: Titlekit::Specification

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

Direct Known Subclasses

Have, Want

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpecification

Returns a new instance of Specification.



7
8
9
10
11
12
13
14
15
16
# File 'lib/titlekit/specification.rb', line 7

def initialize
  @encoding = nil
  @file = nil
  @fps = nil
  @references = {}
  @subtitles = []
  @track = nil

  return self
end

Instance Attribute Details

#subtitlesObject

Only for internal usage by the job control center



5
6
7
# File 'lib/titlekit/specification.rb', line 5

def subtitles
  @subtitles
end

Instance Method Details

#encoding(*args) ⇒ Object

Returns If you omit the argument, it returns the already specified encoding.

Parameters:

  • A (String)

    string specifying the encoding, e.g. ‘utf-8’ or ‘ISO-8859-1’

Returns:

  • If you omit the argument, it returns the already specified encoding



20
21
22
23
24
25
26
27
# File 'lib/titlekit/specification.rb', line 20

def encoding(*args)
  if args.empty?
    return @encoding
  else
    @encoding = args[0]
    return self
  end
end

#file(*args) ⇒ Object

Returns If you omit the argument, it returns the already specified path.

Parameters:

  • A (String)

    string specifying the path to the file

Returns:

  • If you omit the argument, it returns the already specified path



31
32
33
34
35
36
37
38
# File 'lib/titlekit/specification.rb', line 31

def file(*args)
  if args.empty?
    return @file
  else
    @file = args[0]
    return self
  end
end

#fps(*args) ⇒ Object

Returns If you omit the argument, it returns the already specified fps.

Parameters:

  • A (Float)

    float specifying the frames per second, e.g. 23.976

Returns:

  • If you omit the argument, it returns the already specified fps



53
54
55
56
57
58
59
60
# File 'lib/titlekit/specification.rb', line 53

def fps(*args)
  if args.empty?
    return @fps
  else
    @fps = args[0]
    return self
  end
end

#reference(name, *args, hours: nil, minutes: nil, seconds: nil, milliseconds: nil, srt_timecode: nil, ssa_timecode: nil, ass_timecode: nil) ⇒ Object

Places a named reference (in the form of a string or a symbol) on a timecode specified by either hours, minutes, seconds or milliseconds.

Its typical use-case is to reference a specific subtitle you can recognize in both the movie and your subtitle file, where usually for the subtitle file (represented by Have) you will reference the subtitle index and for the movie (represented by Want) you will reference the timecode that is displayed when the line occurs in the movie.

Examples:

Referencing a timecode by hours

have.reference('Earl grey, hot', hours: 0.963)

Referencing a timecode by seconds

have.reference('In a galaxy ...', seconds: 14.2)

Referencing a timecode by an SRT-style timecode

have.reference('In a galaxy ...', srt_timecode: '00:00:14,200')

Referencing a timecode by an ASS-style timecode

have.reference('In a galaxy ...', ass_timecode: '0:00:14,20')

Referencing a timecode by an SSA-style timecode

have.reference('In a galaxy ...', ssa_timecode: '0:00:14,20')

Symbols can be used as references as well!

have.reference(:narrator_begins, minutes: 9.6)

Parameters:

  • name (String, Symbol)

    The name of the reference

  • hours (Float) (defaults to: nil)
  • minutes (Float) (defaults to: nil)
  • seconds (Float) (defaults to: nil)
  • milliseconds (Float) (defaults to: nil)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/titlekit/specification.rb', line 101

def reference(name,
              *args,
              hours: nil,
              minutes: nil,
              seconds: nil,
              milliseconds: nil,
              srt_timecode: nil,
              ssa_timecode: nil,
              ass_timecode: nil)

  @references[name] = case
  when hours
    { timecode: hours * 3600 }
  when minutes
    { timecode: minutes * 60 }
  when seconds
    { timecode: seconds }
  when milliseconds
    { timecode: milliseconds / 1000 }
  when srt_timecode
    { timecode: Titlekit::SRT.parse_timecode(srt_timecode) }
  when ssa_timecode
    { timecode: Titlekit::SSA.parse_timecode(ssa_timecode) }
  when ass_timecode
    { timecode: Titlekit::ASS.parse_timecode(ass_timecode) }
  end

  return self
end

#referencesObject

Returns all named references you have specified



63
64
65
# File 'lib/titlekit/specification.rb', line 63

def references
  return @references
end

#track(*args) ⇒ Object

Returns If you omit the argument, it returns the already specified track.

Parameters:

  • A (String)

    string specifying the track identifier

Returns:

  • If you omit the argument, it returns the already specified track



42
43
44
45
46
47
48
49
# File 'lib/titlekit/specification.rb', line 42

def track(*args)
  if args.empty?
    return @track
  else
    @track = args[0]
    return self
  end
end