Notes:
- Use functional
Enumerable#map
instead of imperative pattern "obj = []"obj = []
+Enumerable#each
+Array#<<
. - Use Kernel#Hash to build a hash from its pairs. However,Note that this method is very ugly, if and some prefer a more OOP approach use, in that case check Enumerable#mash from Facets.
- Use
nokogiri_node.text
. - Arguments in blocks can be unpacked.
I'd write:
require 'nokogiri'
require 'facets'
def get_training_queue(xml_data)
xml_data.xpath("//row").map do |skill_in_queue|
skill_in_queue.attributes.mash do |name, attribute|
[name.to_sym, attribute.text]
end
end
end
All those each
s and in-place updates show that you think in imperative terms instead of functional, check this wiki page.