Created
          October 25, 2013 07:52 
        
      - 
      
- 
        Save TimLang/7150968 to your computer and use it in GitHub Desktop. 
    Group to hash by some rule
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | data = [{"weight"=>0, "id"=>8153, "text"=>"submits", "blank_id"=>"color1"}, {"weight"=>100, "id"=>3559, "text"=>"reveals", "blank_id"=>"color1"}, {"weight"=>0, "id"=>9458, "text"=>"launches", "blank_id"=>"color1"}, {"weight"=>0, "id"=>552, "text"=>"generates", "blank_id"=>"color1"}, {"weight"=>0, "id"=>2495, "text"=>"audience", "blank_id"=>"color2"}, {"weight"=>0, "id"=>8127, "text"=>"officials", "blank_id"=>"color2"}, {"weight"=>0, "id"=>8535, "text"=>"partners", "blank_id"=>"color2"}, {"weight"=>100, "id"=>6025, "text"=>"staff", "blank_id"=>"color2"}, {"weight"=>100, "id"=>2260, "text"=>"while", "blank_id"=>"color3"}, {"weight"=>0, "id"=>2920, "text"=>"because", "blank_id"=>"color3"}, {"weight"=>0, "id"=>4023, "text"=>"for", "blank_id"=>"color3"}, {"weight"=>0, "id"=>6816, "text"=>"although", "blank_id"=>"color3"}, {"weight"=>0, "id"=>113, "text"=>"exits", "blank_id"=>"color4"}, {"weight"=>100, "id"=>3528, "text"=>"shortages", "blank_id"=>"color4"}, {"weight"=>0, "id"=>1980, "text"=>"absences", "blank_id"=>"color4"}, {"weight"=>0, "id"=>3554, "text"=>"departures", "blank_id"=>"color4"}, {"weight"=>100, "id"=>4143, "text"=>"surveyed", "blank_id"=>"color5"}, {"weight"=>0, "id"=>3519, "text"=>"searched", "blank_id"=>"color5"}, {"weight"=>0, "id"=>2918, "text"=>"exposed", "blank_id"=>"color5"}, {"weight"=>0, "id"=>1059, "text"=>"exploited", "blank_id"=>"color5"}, {"weight"=>0, "id"=>1908, "text"=>"collective", "blank_id"=>"color6"}, {"weight"=>100, "id"=>6053, "text"=>"private", "blank_id"=>"color6"}, {"weight"=>0, "id"=>7871, "text"=>"personal", "blank_id"=>"color6"}, {"weight"=>0, "id"=>1839, "text"=>"civil", "blank_id"=>"color6"}, {"weight"=>0, "id"=>6856, "text"=>"confronted", "blank_id"=>"color7"}, {"weight"=>0, "id"=>8339, "text"=>"conformed", "blank_id"=>"color7"}, {"weight"=>100, "id"=>4999, "text"=>"concerned", "blank_id"=>"color7"}, {"weight"=>0, "id"=>9338, "text"=>"confused", "blank_id"=>"color7"}, {"weight"=>0, "id"=>7236, "text"=>"bind", "blank_id"=>"color8"}, {"weight"=>0, "id"=>3723, "text"=>"attain", "blank_id"=>"color8"}, {"weight"=>0, "id"=>1346, "text"=>"transfer", "blank_id"=>"color8"}, {"weight"=>100, "id"=>8195, "text"=>"recruit", "blank_id"=>"color8"}, {"weight"=>0, "id"=>2956, "text"=>"Lest", "blank_id"=>"color9"}, {"weight"=>0, "id"=>2544, "text"=>"Unless", "blank_id"=>"color9"}, {"weight"=>0, "id"=>9495, "text"=>"Before", "blank_id"=>"color9"}, {"weight"=>100, "id"=>9980, "text"=>"As", "blank_id"=>"color9"}, {"weight"=>0, "id"=>8144, "text"=>"with", "blank_id"=>"color10"}, {"weight"=>100, "id"=>2238, "text"=>"for", "blank_id"=>"color10"}, {"weight"=>0, "id"=>9411, "text"=>"on", "blank_id"=>"color10"}, {"weight"=>0, "id"=>5243, "text"=>"by", "blank_id"=>"color10"}, {"weight"=>0, "id"=>3319, "text"=>"dominate", "blank_id"=>"color11"}, {"weight"=>0, "id"=>2520, "text"=>"stretch", "blank_id"=>"color11"}, {"weight"=>0, "id"=>550, "text"=>"enforce", "blank_id"=>"color11"}, {"weight"=>100, "id"=>594, "text"=>"intensify", "blank_id"=>"color11"}, {"weight"=>0, "id"=>6363, "text"=>"creative", "blank_id"=>"color12"}, {"weight"=>100, "id"=>6101, "text"=>"technical", "blank_id"=>"color12"}, {"weight"=>0, "id"=>6685, "text"=>"narrative", "blank_id"=>"color12"}, {"weight"=>0, "id"=>8799, "text"=>"physical", "blank_id"=>"color12"}, {"weight"=>100, "id"=>2998, "text"=>"priority", "blank_id"=>"color13"}, {"weight"=>0, "id"=>7117, "text"=>"option", "blank_id"=>"color13"}, {"weight"=>0, "id"=>6721, "text"=>"challenge", "blank_id"=>"color13"}, {"weight"=>0, "id"=>8388, "text"=>"judgment", "blank_id"=>"color13"}, {"weight"=>0, "id"=>4036, "text"=>"procedures", "blank_id"=>"color14"}, {"weight"=>0, "id"=>8008, "text"=>"academies", "blank_id"=>"color14"}, {"weight"=>0, "id"=>1737, "text"=>"thoughts", "blank_id"=>"color14"}, {"weight"=>100, "id"=>374, "text"=>"subjects", "blank_id"=>"color14"}, {"weight"=>0, "id"=>1347, "text"=>"until", "blank_id"=>"color15"}, {"weight"=>0, "id"=>8565, "text"=>"since", "blank_id"=>"color15"}, {"weight"=>0, "id"=>2451, "text"=>"whereas", "blank_id"=>"color15"}, {"weight"=>100, "id"=>8782, "text"=>"if", "blank_id"=>"color15"}, {"weight"=>100, "id"=>2438, "text"=>"rate", "blank_id"=>"color16"}, {"weight"=>0, "id"=>8001, "text"=>"discuss", "blank_id"=>"color16"}, {"weight"=>0, "id"=>6986, "text"=>"order", "blank_id"=>"color16"}, {"weight"=>0, "id"=>664, "text"=>"observe", "blank_id"=>"color16"}, {"weight"=>0, "id"=>7528, "text"=>"typical", "blank_id"=>"color17"}, {"weight"=>0, "id"=>3689, "text"=>"positive", "blank_id"=>"color17"}, {"weight"=>100, "id"=>1242, "text"=>"particular", "blank_id"=>"color17"}, {"weight"=>0, "id"=>5480, "text"=>"general", "blank_id"=>"color17"}, {"weight"=>100, "id"=>2568, "text"=>"highlighted", "blank_id"=>"color18"}, {"weight"=>0, "id"=>6426, "text"=>"prescribed", "blank_id"=>"color18"}, {"weight"=>0, "id"=>3355, "text"=>"focused", "blank_id"=>"color18"}, {"weight"=>0, "id"=>3041, "text"=>"touched", "blank_id"=>"color18"}, {"weight"=>0, "id"=>1547, "text"=>"masses", "blank_id"=>"color19"}, {"weight"=>100, "id"=>9614, "text"=>"workforce", "blank_id"=>"color19"}, {"weight"=>0, "id"=>9313, "text"=>"faculty", "blank_id"=>"color19"}, {"weight"=>0, "id"=>3594, "text"=>"communities", "blank_id"=>"color19"}, {"weight"=>0, "id"=>6031, "text"=>"what", "blank_id"=>"color20"}, {"weight"=>0, "id"=>8012, "text"=>"whom", "blank_id"=>"color20"}, {"weight"=>100, "id"=>5031, "text"=>"where", "blank_id"=>"color20"}, {"weight"=>0, "id"=>2027, "text"=>"why", "blank_id"=>"color20"}]; | |
| data.inject({}){|r, h| r["#{h['blank_id']}"] = [] unless r["#{h['blank_id']}"] ; r["#{h['blank_id']}"] << h;r} | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment