ruby - Loop through array of hashes with rails -


So I try to catch all high school and graduate schools I am doing this from the array of hash:

  "education": [["school": {"id": "110703012290674", "name": "kuskpsignignith malm"), "year "": "Name": "name": "name": "2009"}, "type": "high school"}, {"school": {"id": "11281248539 9398", "name": " Malmuy University "", "year": {"id": "118118634930920", "name": "2012"}, "concentration": [{"id": "104076956295773", "name": "computer science"} ], "Type": "Graduate School "Programs", "Details": "Kurson Focusare PA Metadars and Technik Developers of Webblicensecher Made HJAU" LP and HTML5 ":" {{"id": "1650 93923542525", "Name": "Programming" Like this:  
  If auth ["extra"] ["raw_info"] ["education"] # hash / Array Element 0 If Ath ["extra"] ["raw_ology"] ["education"] [0] ["type"] == "high school" user.highschool_name = auth ["extra"] ["raw_info"] [ "Education"] [0] ["school"] ["name"] if (! Auth ["extra"] empty? & Amp; Auth ["extra"] ["raw_info"] ["education"] [0] ["school"] empty?) User.highschool_year = auth ["extra"] ["raw_info"] ["education"] [0] ["Year"] ["name"] If (Auth ["extra"] blank? And AUT ["extra"] ["raw_info"] ["education"] [0] ["year"] blank?) Alsf Proof ["extra"] ["raw_info"] ["education"] [0] ["type"] == "graduate school" user.graduateschool_name = auth ["extra"] ["raw_info"] ["education"] [0] ["school"] ["name"] If (! Auth ["extra"] blank? & Amp; auth ["extra"] ["raw_info"] ["education"] [0] ["school" ] Blank?) User graduate school _yyyy = auth ["extr A "[" raw_info "] [" education "] [0] [" year "] [" name "] If (! Auth [" extra "] Blank? & Amp; auth [" extra "] [" raw_info "] [" Education "] [0] [" year "] blank?) End # hash / Aar element 1 If Ath [" extra "] [" raw_info "] [" Education "] [1] [" Type "] ==" high school "user.highschool_name = auth [" extra "] [" raw_info "] [" education "] [1] [" school "] [" name "] if (! Auth [" extra "] Blank? & Amp; & Auth ["extra"] ["raw_info"] ["Education"] [1] ["School"] Blank?) User.highschool_year = auth ["extra"] ["raw_info"] ["education"] [1] ["year"] ["name"] If (! Auth ["extra"] blank? & Amp; ["Extra"] ["raw_info"] ["education"] [1] ["year"] empty?) Alsph as ["extra"] ["raw_ology"] ["education"] [1] [ "Type"] == "Graduate school" user.graduateschool_name = auth ["extra"] ["raw_info"] ["education"] [1] ["school"] ["name"] If (! Auth ["extra "Blank"? Amp; auth ["extra"] ["raw_info"] ["education"] [1] ["school"] blank?) User.graduateschool_year = auth ["extra"] ["raw_info"] [ "Education"] [1] ["name"] if (! Auth ["extra"] blank? & Amp; auth ["extra"] ["raw_info"] ["education"] [1] ["Work Shi?]? Empty?) End?   

Is there any more efficient way to do this, like some fanatics loop? Any great ideas?

Yes, of course, you should use a loop. It seems that you want something like this:

  if edu = auth ["extra"] ["raw_info"] ["education"] edu.each do | E If E ["type"] == "high school" user.highschool_name = e ["school"] ["name"] if (! Auth ["extra"] blank? & Amp ;;! [[School "] .blank?) User.highschool_year = e ["year"] ["name"] if (! Auth ["extra"] empty? & Amp; E; ["year"] blank?] Elsf E ["type"] == "Graduate School" user.graduateschool_name = e ["school"] ["name"] if (! Auth ["extra"] blank? & Amp; Amp; E ["school"] blank?) User.graduateschool_year = E ["year"] ["name"] If (! Auth ["extra"] blank?? E ["year"]. Blank?) End end   

Update

OK, even simpler version (tips from Tokel ("Auth [" extra "] [" raw_info "] [" education "]] []). Every" e "[" postgraduate school "name, : Graduate school_yure] end user.send ("e-mail", "e-mail", "e-mail", "# {Nameprop} =", e ["school"] ["name"])! ["School"]. Empty? User.send ("# {yearprop} =", ["year"] ["name"]) if! E ["year"] blank? End

Comments