lib/handbrake/titles.rb in handbrake-0.2.0 vs lib/handbrake/titles.rb in handbrake-0.2.1

- old
+ new

@@ -34,10 +34,11 @@ def self.from_output(output) self.new.tap do |titles| titles.raw_output = output titles.raw_tree.children. collect { |title_node| Title.from_tree(title_node) }. + each { |title| title.collection = titles }. each { |title| titles[title.number] = title } end end ## @@ -122,10 +123,14 @@ # @return [Boolean] Whether HandBrake considers this title the # "main feature". attr_writer :main_feature ## + # @return [Titles] The collection this title belongs to. + attr_accessor :collection + + ## # Creates a new instance from the given scan subtree. # # @see Titles.from_output # @param [Tree::TreeNode] title_node # @return [Title] a new, fully initialized instance @@ -135,12 +140,15 @@ 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 } - title.main_feature = title_node.children.detect { |c| c.name =~ /Main Feature/ } + # !! 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 ## # @return [Boolean] Whether HandBrake considers this title the @@ -176,9 +184,13 @@ ## # @return [Fixnum] The chapter number for this chapter (a positive # integer) attr_accessor :number + + ## + # @return [Title] The title that contains this chapter + attr_accessor :title ## # Creates a new instance from the given title subtree. # # @see Title.from_tree