Nokogiri allows you to access the XML using CSS selectors. When your selectors match more than one thing, Nokogiri returns an array of those things. Here, we are using Ruby's Array#collect
method to return a new array of items based on what the block returns:
lists = system.css('lists list').collect do |list|
{ 'critical' => list['critical'], 'access' => list['access'] }
end
networks = system.css('networks network').collect do |network|
{ 'network' => network['name'] }
end
This should give you the output you are looking for.