我有一个文件夹,其中包含许多带有 xml 文件的子文件夹,其中包含有关英雄联盟冠军的信息。我的最终目标是拥有一个列出所有英雄联盟冠军的索引页面和一个展示页面,其中包含每个英雄的详细信息。
在我学习 Rails 之前,我尝试过这样做,这就是我目前所拥有的。
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
逐行分解...
#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.
理想情况下,我想手动解析它,但我愿意使用其他现有的库。我提到使用 JSON。
其次,每个冠军的子文件夹中都包含图像,我想知道是否需要提取每个图像并将其放入 assets/images 文件夹中。
第三,在 Rails 4.0 中所有的冠军 xml 文件都放在哪里
这是一个很大的问题,我知道,但请随意部分回答。
谢谢,伊恩