Class MyDB
In: db/mydb.rb
Parent: Object
Methods
getln    new    readdb   
Attributes
:artists  [R] 
:discs  [R] 
:discsByArtist  [R] 
:discsInOrder  [R] 
:sortinfo  [R] 
:tracks  [R] 
:tracks  [R] 
Public Class methods
new(fn = nil)

Initialize from ASCII file

# File db/mydb.rb, line 59
  def initialize(fn = nil)
    @discs = nil
    @artists = nil
    @discsByArtist = nil
    @discsInOrder = nil
    @tracks = nil
    @sortinfo = nil
    begin
      File.open(fn, File::RDONLY) { 
	|f| 
	lines = f.readlines.map { |l| l.strip }
	readdb(lines.delete_if { |l| l =~ /^#/ || l =~ /^$/ })
      } if !fn.nil?
    rescue
      raise
    end
  end
Private Instance methods
readdb(lines)

Read ASCII DB file into memory from array of split lines.

# File db/mydb.rb, line 84
  def readdb(lines)
    begin
      l = []
      si = nil
      lastinitial = ""
      @discs = Hash.new
      @artists = Array.new
      @discsByArtist = Hash.new
      @discsInOrder = Array.new
      @sortinfo = Hash.new
      while lines.size > 0
	l = getln(lines) until l.size == 1 && l.first == "disc"
	d = Disc.new
	t = Array.new
	l = getln(lines)
	while l.first != "track"
	  case l.first
	  when "dartist"
	    d.dartist = l.last
	  when "dtitle"
	    d.dtitle = l.last
	  when "discid"
	    d.key = l.last
	  when "dyear"
	    d.dyear = l.last
	  when "dsecs"
	    d.dsecs = l.last
	  when "dsortby"
	    si = SortInfo.new
	    si.initial = l.last
	  end
	  l = getln(lines)
	end
	while l.first == "track"
	  trknum = l.last
	  tmp = Hash.new
	  l = getln(lines)
	  while l.first =~ /\+\w+/
	    case l.first
	    when "+artist"
	      tmp["a"] = l.last
	    when "+title"
	      tmp["t"] = l.last
	    when "+path"
	      tmp["p"] = l.last
	    when "+secs"
	      tmp["s"] = l.last
	    end
	    l = getln(lines)
	  end
	  if lastinitial != si.initial
	    lastinitial = si.initial
	    @sortinfo[si.initial] = si
	    si.artistnum = @artists.size
	  end
	  s = Song.new(tmp["a"], tmp["t"])
	  t << Track.new(trknum, tmp["p"], tmp["s"], s)
	end
	d.dtracks = t
	@discs[ d.key ] = d
	if @discsByArtist[d.dartist].nil?
	  @artists << d.dartist
	  @discsByArtist[d.dartist] = Array.new 
	end
	@discsByArtist[d.dartist] << d
	@discsInOrder << d
	l = getln(lines) until l.first == "end" && l.last == "disc"
      end
    rescue
      raise
    end
    @tracks = MyTracks.new(@discs)
  end
getln(lines)

Read one line and split into key, value.

# File db/mydb.rb, line 160
  def getln(lines)
    lines.shift.split(/\s+/, 2)
  end