Parsing local XML files using Ruby on Rails 4.0
I have folder that contains many sub folders with xml files that have
information on League of Legends champions. My end goal is to have an
index page that lists all League of Legends champions and a show page with
details on each one.
I tried doing this before I learned Rails and this is what I have so far.
File.open("champion_list.txt", "w") do |file_name|
File.open("champions.txt", "r").each do |folder_name|
folder_name = folder_name.strip
xml = File.open("LoLChampions/data/#{folder_name}/champion.xml").read
file_name.write(xml)
end
end
Line-by-line breakdown...
#open the list of every champion
#read each champion individually and do this to each one
#strips the individual champions of useless text including a ton of /n /br's
#reads the champion file inside of it's folder which is named after the
name of each champion that has been grabbed from the textfile.
#each champion has a folder named the name of the champion and each
champion folder contains images of the champion and a champion.xml file.
Ideally I want to parse this by hand, but i'm open to use other existing
libraries. I mentioned using JSON.
Second, the subfolder for each champion contains images inside and I'm
wondering if I'm going to need to extract every image and put it inside
the assets/images folder.
Third, where do all of the champion xml files go in Rails 4.0
This is a huge question, I know, but feel free to only answer it in parts.
Thanks, Ian
No comments:
Post a Comment