Class: HandBrake::Disc

Inherits:
Object
  • Object
show all
Defined in:
lib/handbrake/disc.rb

Overview

An object representation of the output from HandBrakeCLI's --scan mode.

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Disc

Returns a new instance of Disc.



39
40
41
42
# File 'lib/handbrake/disc.rb', line 39

def initialize(name=nil)
  @name = name
  @titles = {}
end

Instance Attribute Details

#nameString

The name of the disc.

Returns:

  • (String)


37
38
39
# File 'lib/handbrake/disc.rb', line 37

def name
  @name
end

#raw_outputString?

The HandBrakeCLI scan output from which this instance was parsed, if available.

Returns:

  • (String, nil)


18
19
20
# File 'lib/handbrake/disc.rb', line 18

def raw_output
  @raw_output
end

#raw_treeString? (readonly)

A tree representing the indented output at the end of the HandBrakeCLI scan output, if available.

Returns:

  • (String, nil)


25
26
27
# File 'lib/handbrake/disc.rb', line 25

def raw_tree
  @raw_tree
end

#titlesHash<Fixnum, Title> (readonly)

The titles in the disc. The keys are the title numbers.

Returns:



31
32
33
# File 'lib/handbrake/disc.rb', line 31

def titles
  @titles
end

Class Method Details

.from_output(output) ⇒ Disc

Builds a new HandBrake::Disc instance from the output of HandBrakeCLI --scan.

Parameters:

  • output (String)

    the raw contents from the scan

Returns:

  • (Disc)

    a new, completely initialized title catalog



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/handbrake/disc.rb', line 50

def self.from_output(output)
  name = File.basename(
    output.split("\n").grep(/hb_scan/).first.scan(/path=([^,]*),/).first.first)
  self.new(name).tap do |disc|
    disc.raw_output = output
    disc.raw_tree.children.
      collect { |title_node| Title.from_tree(title_node) }.
      each { |title| title.disc = disc }.
      each { |title| disc.titles[title.number] = title }
  end
end

Instance Method Details

#to_yaml_propertiesObject



75
76
77
# File 'lib/handbrake/disc.rb', line 75

def to_yaml_properties
  %w(@name  @titles)
end