Parser, part deux
Fixed the nested <item> blocks. Ran into another problem where it didn’t parse nested characters and their items properly, then yet another where some Gifts of Khaine (and probably other things I haven’t seen in either list) are essentially nested worthlessness. Fixed code for it:
def parseitem(d, addto) added = addto.add_element(d.attributes["name"].gsub(/\s+/, '')).add_text(d.attributes["description"].gsub(/\./, '')) d.elements.each('link') do |ele| unless ele.attributes["name"] =~ /(Worker|Helper|Cost|Left)/ if !ele.attributes["description"].nil? added.add_element(ele.attributes["name"].gsub(/\s+/, '')).add_text(ele.attributes["description"]) else #This is necessary for some Gifts of Khaine, apparently if added.text == ele.attributes["name"] print "Found duplicated #{added.text}!\n\n" added.text = '' end added.add_element(ele.attributes["name"].gsub(/\s+/, '')).add_text("True") end end end end def parsenested(process, addto) #Try to guess if it's a champion, character in the unit, or item process.elements.each('entity') do |d| if d.attributes["statset"] =~ /Normal/ #It's a character, crew, or mount. Figure out which if d.attributes["totalcost"] !~ /^0/ #It's a champion or character adder = addto.add_element("champion") puts "Found champ\n" parse(d, adder) else #It's crew or the like adder = addto.add_element("crew") puts "Found crew\n" parse(d, adder) end else #It's an item puts "Found item\n" if addto.elements["item"].nil? @adder = addto.add_element("item") end parseitem(d, @adder) end end end
No Comments
No comments yet.
RSS feed for comments on this post. TrackBack URI
Leave a comment
You must be logged in to post a comment.