Currently I am getting an array of hashes by doing this:
f = File.open("public/odds/test.xml")
xml = Nokogiri::XML(f)
path = "//demo/test1/test"
xml.xpath(path).map do |x|
{'country' => x.parent}
end
A sample of my result for this:
[{"country"=>"france"}, {"country"=>"singapore"}, {"country"=>"thailand"}]
Now as I have different xml files, I am doing a loop to go through all the files:
@files = ['a', 'b', 'c']
@files.each do |file|
f = File.open("public/odds/#{file}.xml)
xml = Nokogiri::XML(f)
path = "//demo/test1/test"
xml.xpath(path).map do |x|
{'country' => x.parent}
end
As it is looping through each file, I expect to get 3 different results like this [{"country"=>"france"}, {"country"=>"singapore"}, {"country"=>"thailand"}]. How can I merge them together so that they are in 1 array?