lib/handbrake/titles.rb in handbrake-0.0.2 vs lib/handbrake/titles.rb in handbrake-0.1.0
- old
+ new
@@ -134,11 +134,12 @@
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) }
+ collect { |ch_node| Chapter.from_tree(ch_node) }.
+ inject({}) { |h, ch| h[ch.number] = ch; h }
title.main_feature = title_node.children.detect { |c| c.name =~ /Main Feature/ }
end
end
##
@@ -147,13 +148,20 @@
def main_feature?
@main_feature
end
##
- # @return [Array<Chapter>] The chapters into which the title is
- # divided.
+ # @return [Hash<Fixnum,Chapter>] The chapters into which the title is
+ # divided, indexed by chapter number (a positive integer).
def chapters
- @chapters ||= []
+ @chapters ||= {}
+ end
+
+ ##
+ # @return [Array<Chapter>] The chapters of the title, sorted by
+ # chapter number.
+ def all_chapters
+ chapters.keys.sort.collect { |k| chapters[k] }
end
end
##
# The metadata about a single chapter in a title of a DVD.