Class: HandBrake::Title

Inherits:
Object
  • Object
show all
Includes:
DurationAsSeconds
Defined in:
lib/handbrake/titles.rb

Overview

Metadata about a single DVD title.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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).



163
164
165
# File 'lib/handbrake/titles.rb', line 163

def chapters
  @chapters ||= {}
end

#collectionTitles

Returns The collection this title belongs to.

Returns:

  • (Titles)

    The collection this title belongs to.



129
130
131
# File 'lib/handbrake/titles.rb', line 129

def collection
  @collection
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"



115
116
117
# File 'lib/handbrake/titles.rb', line 115

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".



125
126
127
# File 'lib/handbrake/titles.rb', line 125

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).



110
111
112
# File 'lib/handbrake/titles.rb', line 110

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:



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/handbrake/titles.rb', line 137

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.



170
171
172
# File 'lib/handbrake/titles.rb', line 170

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".



156
157
158
# File 'lib/handbrake/titles.rb', line 156

def main_feature?
  @main_feature
end