class Titles

Public Class Methods

new(filename, target_directory: 'titles') click to toggle source
# File lib/got_mp3.rb, line 442
def initialize(filename, target_directory: 'titles')
  @titles = File.read filename
  @target_directory = target_directory
end

Public Instance Methods

split(target_directory: @target_directory) click to toggle source
# File lib/got_mp3.rb, line 455
def split(target_directory: @target_directory)

  FileUtils.mkdir_p @target_directory
  a = @titles.strip.split(/(?=^#)/)

  a.each do |x|

    filename = x.lines.first.chomp[/(?<=# cd ).*/i].strip + '.txt'
    puts 'processing file ' + filename.inspect
    heading = x.lstrip.lines.first

    tracks = x.strip.lines[1..-1].map.with_index do |line, i|
      "%02d. %s" % [i+1, line]
    end

    File.write File.join(target_directory, filename), heading + tracks.join

  end

  puts 'split done'

end
titleize() click to toggle source
# File lib/got_mp3.rb, line 447
def titleize()
  @titles.gsub(/[\w']+/) {|x| x[0].upcase + x[1..-1]}
end
titleize!() click to toggle source
# File lib/got_mp3.rb, line 451
def titleize!()
  @titles.gsub!(/[\w']+/) {|x| x[0].upcase + x[1..-1]}
end