Class BuildDB
In: db/builddb.rb
db/writedb.rb
db/readnames.rb
db/cddb-listdiscs.rb
Parent: Object

Load method for MyDB.

Methods
initdb    listdiscs    new    readnames    writedb    writedisc   
Attributes
:mydiscs  [RW] 
Included modules
DBSort
Public Class methods
new()
# File db/builddb.rb, line 43
  def initialize()
    @reNames =
      @mydiscs = nil
  end
Public Instance methods
initdb()

Load discs according to config file.

# File db/writedb.rb, line 59
  def initdb()
    @mydiscs = listdiscs
    @lastinitial = ""
  end
writedisc(f, disc)

Write into for disc to file f.

# File db/writedb.rb, line 65
  def writedisc(f, disc)
    f.puts("#")
    f.puts("## #{disc.dartist}")
    f.puts("## #{disc.dtitle}")
    f.puts("disc")
    f.puts("  dartist\t#{disc.dartist}")
    f.puts("  dtitle\t#{disc.dtitle}")
    f.puts("  discid\t#{disc.key}")
    f.puts("  dyear\t#{disc.dyear}")
    f.puts("  dsecs\t#{disc.dsecs}")
    initial = sortname(disc.dartist)[0,1]
    f.puts("  dsortby\t#{initial}")
    @lastinitial = initial if @lastinitial != initial
    disc.dtracks.each {
      |t|
      next if t.nil?
      f.puts("track #{t.trk}")
      artist = t.song.artist
      f.puts("  +artist\t#{t.song.artist}")
      f.puts("  +title\t#{t.song.title}")
      f.puts("  +path\t#{t.path}")
      f.puts("  +secs\t#{t.secs}")
    }
    f.puts("end disc")
    f.flush
  end
writedb(f)

Write the whole database to file f.

# File db/writedb.rb, line 93
  def writedb(f)
    @sortcache = Hash.new
    @reNames = Regexp.new(readnames)
    discs = @mydiscs.values.sort {
      |a,b|
      (sortname(a.dartist) + a.dyear.to_s + sorttitle(a.dtitle)) <=>
	(sortname(b.dartist) + b.dyear.to_s + sorttitle(b.dtitle))
    }
    discs.each { |disc| writedisc(f, disc) }
#    @mydiscs.each_value { |disc| writedisc(f, disc) }
  end
Private Instance methods
readnames()

Load tables containing first names to strip. Make a big honking regular expression out of the whole thing.

# File db/readnames.rb, line 46
  def readnames()
    systab = File.join(INSTALLBASE, "nametab")
    usrtab = File.join(CONFDIR, "nametab")
    names = []
    [ systab, usrtab ].each {
      |fn|
      next if ! File.file?(fn)
      IO.foreach(fn) {
	|l| names.push(l.strip.downcase)
      }
    }
    strexpr = "^(" +
      names.sort{ |a,b| b.size<=>a.size}.uniq.join("|") + 
      ")\s+"
  end
listdiscs()
# File db/cddb-listdiscs.rb, line 47
  def listdiscs()
    cddb = Config.instance.db["cddb"]
    mp3paths = Config.instance.db["loaddirs"]
    discs = MyDiscs.new(cddb)
    mp3paths.each { |dir| discs.loaddir(File.expand_path(dir)) }
    return discs
  end