Database Reference
In-Depth Information
@artist = nil
@album = nil
@track = nil
@tag = nil
@buffer = nil
end
def on _ start _ element(element, attributes)
~
case element
when 'artist'
@artist = { :albums => [] }
@stack.push @artist
when 'album'
@album = { :tracks => [] }
@artist[:albums].push @album
@stack.push @album
when 'track'
@track = { :tags => [] }
@album[:tracks].push @track
@stack.push @track
when 'tag'
@tag = {}
@track[:tags].push @tag
@stack.push @tag
when 'Artists' , 'Albums' , 'Tracks' , 'Tags'
# ignore
else
@buffer = []
end
end
def on _ characters(chars)
@buffer << chars unless @buffer.nil?
end
def on _ end _ element(element)
case element
when 'artist'
@stack.pop
@artist[ ' _ id' ] = @artist[ 'id' ] # Jamendos artist-id als doc- _ id verwenden
@artist[:random] = rand
@db.save _ doc(@artist, false, true)
@count += 1
if !@max.nil? && @count >= @max
on _ end _ document
end
if @count % 500 == 0
puts " #{@count} records inserted"
end
when 'album' , 'track' , 'tag'
top = @stack.pop
top[:random] = rand
when 'Artists' , 'Albums' , 'Tracks' , 'Tags'
# ignorieren
else
if @stack[-1] && @buffer
@stack[-1][element] = @buffer.join.force _ encoding( 'utf-8' )
@buffer = nil
end
end
end
Search WWH ::




Custom Search