Created
November 29, 2011 20:23
-
-
Save rafaelp/1406310 to your computer and use it in GitHub Desktop.
Como refatorar esse método?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# conteúdo do CSV | |
SF,Técnico Legislativo,Direito Constitucional,Constitucionalismo | |
SF,Técnico Legislativo,Direito Constitucional,Teoria do Estado | |
# método para refatorar | |
def self.concourses_from_file(file_path) | |
return @concourses unless @concourses.nil? | |
@concourses = {} | |
CSV.foreach(file_path) do |row| | |
@concourses[row[0].upcase] ||= {} | |
@concourses[row[0].upcase][row[2]] ||= [] | |
@concourses[row[0].upcase][row[2]] << row[3] | |
end | |
@concourses | |
end | |
# hash esperado | |
{"SF"=>{"Direito Constitucional"=>["Constitucionalismo", "Teoria do Estado"]}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tenta isso se estiver usando ruby 1.9