Class: HandBrake::Title

Inherits:
Object
  • Object
show all
Includes:
ConstructWithProperties, DurationAsSeconds
Defined in:
lib/handbrake/disc.rb

Overview

Metadata about a single DVD title.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConstructWithProperties

#initialize

Methods included from DurationAsSeconds

#seconds

Instance Attribute Details

#chaptersHash<Fixnum,Chapter>

Returns The chapters into which the title is divided, indexed by chapter number (a positive integer).

Returns:

  • (Hash<Fixnum,Chapter>)

    The chapters into which the title is divided, indexed by chapter number (a positive integer).



202
203
204
# File 'lib/handbrake/disc.rb', line 202

def chapters
  @chapters ||= {}
end

#discDisc

Returns The disc this title belongs to.

Returns:

  • (Disc)

    The disc this title belongs to.



168
169
170
# File 'lib/handbrake/disc.rb', line 168

def disc
  @disc
end

#durationString

Returns The duration of the title in the format "hh:mm:ss".

Returns:

  • (String)

    The duration of the title in the format "hh:mm:ss"



154
155
156
# File 'lib/handbrake/disc.rb', line 154

def duration
  @duration
end

#main_feature=(value) ⇒ Boolean (writeonly)

Returns Whether HandBrake considers this title the "main feature".

Returns:

  • (Boolean)

    Whether HandBrake considers this title the "main feature".



164
165
166
# File 'lib/handbrake/disc.rb', line 164

def main_feature=(value)
  @main_feature = value
end

#numberFixnum

Returns The title number of this title (a positive integer).

Returns:

  • (Fixnum)

    The title number of this title (a positive integer).



149
150
151
# File 'lib/handbrake/disc.rb', line 149

def number
  @number
end

Class Method Details

.from_tree(title_node) ⇒ Title

Creates a new instance from the given scan subtree.

Parameters:

  • title_node (Tree::TreeNode)

Returns:

  • (Title)

    a new, fully initialized instance

See Also:

  • Titles.from_output


176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/handbrake/disc.rb', line 176

def self.from_tree(title_node)
  self.new.tap do |title|
    title.number = title_node.name.scan(/title (\d+)/).first.first.to_i
    title.duration = title_node.children.
      detect { |c| c.name =~ /duration/ }.name.
      scan(/duration: (\d\d:\d\d:\d\d)/).first.first
    title.chapters = title_node['chapters:'].children.
      collect { |ch_node| Chapter.from_tree(ch_node) }.
      tap { |chapters| chapters.each { |c| c.title = title } }.
      inject({}) { |h, ch| h[ch.number] = ch; h }
    # !! is so that there's no reference to the node in the
    # resulting object
    title.main_feature = !!title_node.children.detect { |c| c.name =~ /Main Feature/ }
  end
end

Instance Method Details

#all_chaptersArray<Chapter>

Returns The chapters of the title, sorted by chapter number.

Returns:

  • (Array<Chapter>)

    The chapters of the title, sorted by chapter number.



209
210
211
# File 'lib/handbrake/disc.rb', line 209

def all_chapters
  chapters.keys.sort.collect { |k| chapters[k] }
end

#main_feature?Boolean

Returns Whether HandBrake considers this title the "main feature".

Returns:

  • (Boolean)

    Whether HandBrake considers this title the "main feature".



195
196
197
# File 'lib/handbrake/disc.rb', line 195

def main_feature?
  @main_feature
end