Class: CueChapter::CueChapter

Inherits:
RubyCue::Cuesheet
  • Object
show all
Defined in:
lib/cuechapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(cuesheet, xml_file = nil, image_file = nil, link = nil) ⇒ CueChapter

Returns a new instance of CueChapter.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cuechapter.rb', line 6

def initialize(cuesheet, xml_file=nil, image_file=nil, link=nil)
	super(File.read(cuesheet))
  parse!
  
  if @xml_file.nil?
  	@xml_file=File.path(cuesheet).gsub(File.extname(cuesheet),".xml")
  else
  	@xml_file = xml_file
  end
  
  @image_file = image_file
  @link = link
end

Instance Method Details

#convertObject



20
21
22
# File 'lib/cuechapter.rb', line 20

def convert
	File.open(@xml_file, 'w') { |f| f.write(to_chapter_xml) }
end

#to_chapter_xmlObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cuechapter.rb', line 24

def to_chapter_xml
  xml = Builder::XmlMarkup.new(:indent => 2)

  xml.chapters("version" => "1") {
    songs.each do |song|
      xml.chapter("starttime" => "#{song[:index].minutes}:#{song[:index].seconds}") {
        xml.title "#{song[:performer]} - #{song[:title]}"
        xml.picture "#{@image_file}"
        xml.link "#{@link}"
      }
    end
  }
end