title: Iterate of Rails Object array to create key/value pair
body: <p>I have a rails object <code>network_hosts</code>, which returns all of the network hosts for my application.  Now, I'd like to create a <a href="http://morrisjs.github.io/morris.js/donuts.html" rel="nofollow">Morris.js donut chart</a> that shows the <code>host.os_vendor</code> breakdown (Linux, Windows, Apple, etc.).</p>
  
  <p>So, what's the best way to iterate over an object, extract the OS type, create a <code>type count</code> and return it back into the <code>data</code> attribute which Morris.js relies on to create the donut chart?</p>
  
  <p>Here is a sample of the output for <code>network_hosts</code>:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>[#&lt;NetworkHost id: 80, location_id: 14, mac_address: "70:56:81:C1:7C:FD", ip_address: "10.10.10.122", hostname: "Air1", created_at: "2016-04-14 19:30:20", updated_at: "2016-04-22 16:11:33", deleted_at: nil, os_vendor: "Unknown", nickname: nil, vendor: "Unknown", os: "Unknown", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 10, location_id: 14, mac_address: "C8:E0:EB:3D:2B:B7", ip_address: "10.10.10.129", hostname: "iMac2", created_at: "2014-11-25 23:20:41", updated_at: "2016-04-22 16:11:33", deleted_at: nil, os_vendor: "Unknown", nickname: nil, vendor: "Unknown", os: "Unknown", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 29, location_id: 14, mac_address: "18:B4:30:15:BC:63", ip_address: "10.10.10.130", hostname: "02AA01AC4414076R", created_at: "2015-02-26 02:24:32", updated_at: "2016-04-22 16:11:33", deleted_at: nil, os_vendor: "Unknown", nickname: nil, vendor: "Nest Labs", os: "Unknown", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 30, location_id: 14, mac_address: "00:04:20:F0:6E:9F", ip_address: "10.10.10.135", hostname: "HarmonyHub", created_at: "2015-02-26 02:24:32", updated_at: "2016-04-22 16:11:33", deleted_at: nil, os_vendor: "Linux", nickname: nil, vendor: "Slim Devices", os: "Linux 2.6.17 - 2.6.36", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 2, location_id: 14, mac_address: "DC:9F:DB:E6:CB:A9", ip_address: "10.10.10.100", hostname: "office", created_at: "2014-11-25 23:20:41", updated_at: "2016-05-03 18:30:36", deleted_at: nil, os_vendor: "Unknown", nickname: "Who 1", vendor: "Ubiquiti Networks", os: "Unknown", ignore_date: "2016-05-30 00:09:00", ignore_flag: false&gt;,
   #&lt;NetworkHost id: 27, location_id: 14, mac_address: "74:54:7D:02:53:8C", ip_address: "10.10.10.101", hostname: "Hostname Unknown", created_at: "2015-02-26 02:24:32", updated_at: "2016-05-03 18:30:36", deleted_at: nil, os_vendor: "Linksys", nickname: nil, vendor: "Unknown", os: "Linksys WET54G wireless bridge", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 76, location_id: 14, mac_address: "D0:63:B4:00:5B:40", ip_address: "10.10.10.106", hostname: "OpenELEC", created_at: "2016-02-19 01:03:24", updated_at: "2016-05-02 17:08:28", deleted_at: nil, os_vendor: "Unknown", nickname: "OpenElec", vendor: "Unknown", os: "Unknown", ignore_date: "2016-06-01 17:07:50", ignore_flag: false&gt;,
   #&lt;NetworkHost id: 11, location_id: 14, mac_address: "84:34:97:1C:42:50", ip_address: "10.10.10.137", hostname: "HP1A4DC4", created_at: "2014-11-25 23:20:41", updated_at: "2016-04-22 16:11:33", deleted_at: nil, os_vendor: "HP", nickname: nil, vendor: "Unknown", os: "HP printer: LaserJet CM1312, Photosmart C510a, or ...", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 14, location_id: 14, mac_address: "E8:8D:28:57:AE:22", ip_address: "10.10.10.144", hostname: "time-capsule", created_at: "2014-11-25 23:20:42", updated_at: "2016-04-22 16:11:33", deleted_at: nil, os_vendor: "Apple", nickname: nil, vendor: "Unknown", os: "Apple AirPort Extreme WAP or Time Capsule NAS devi...", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 75, location_id: 14, mac_address: "00:14:BF:E0:A0:05", ip_address: "10.10.10.2", hostname: "Hostname Unknown", created_at: "2016-02-18 22:48:01", updated_at: "2016-04-22 16:11:33", deleted_at: nil, os_vendor: "Linux", nickname: "test", vendor: "Cisco-Linksys", os: "DD-WRT v23 - v24-sp2 (Linux 2.4.20 - 2.4.37)", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 4, location_id: 14, mac_address: "DC:9F:DB:E6:CF:C1", ip_address: "10.10.10.104", hostname: "main", created_at: "2014-11-25 23:20:41", updated_at: "2016-05-03 18:30:36", deleted_at: nil, os_vendor: "Unknown", nickname: nil, vendor: "Ubiquiti Networks", os: "Unknown", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 28, location_id: 14, mac_address: "18:B4:30:15:BB:76", ip_address: "10.10.10.105", hostname: "02AA01AC451400G4", created_at: "2015-02-26 02:24:32", updated_at: "2016-05-03 18:30:36", deleted_at: nil, os_vendor: "Unknown", nickname: nil, vendor: "Nest Labs", os: "Unknown", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 8, location_id: 14, mac_address: "B8:78:2E:05:E7:F0", ip_address: "10.10.10.118", hostname: "Apple-TV-3", created_at: "2014-11-25 23:20:41", updated_at: "2016-04-22 16:11:33", deleted_at: nil, os_vendor: "Apple", nickname: nil, vendor: "Unknown", os: "Apple iOS 4.4.2 - 5.0.1 (Darwin 11.0.0)", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 24, location_id: 14, mac_address: "74:31:70:0B:56:75", ip_address: "10.10.10.113", hostname: "Hostname Unknown", created_at: "2015-01-29 19:05:44", updated_at: "2016-04-24 14:20:44", deleted_at: nil, os_vendor: "Unknown", nickname: nil, vendor: "Arcadyan Technology", os: "Unknown", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 82, location_id: 14, mac_address: "d2:2a:aa:3e:1e:5a:2d", ip_address: "10.10.10.222", hostname: "Hostname Unknown", created_at: "2016-04-18 17:45:30", updated_at: "2016-04-24 14:20:44", deleted_at: nil, os_vendor: "Unknown", nickname: nil, vendor: "Unknown", os: "Unknown", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 81, location_id: 14, mac_address: "10:9d:07:1b:e4:a7:a8", ip_address: "10.10.10.199", hostname: "Hostname Unknown", created_at: "2016-04-18 16:21:07", updated_at: "2016-04-28 20:49:47", deleted_at: nil, os_vendor: "Linux", nickname: "", vendor: "Unknown", os: "Linux 2.6.32 - 2.6.38", ignore_date: nil, ignore_flag: false&gt;,
   #&lt;NetworkHost id: 1, location_id: 14, mac_address: "4C:E6:76:3F:2F:77", ip_address: "10.10.10.1", hostname: "DD-WRT", created_at: "2014-11-25 23:20:41", updated_at: "2016-05-02 13:25:07", deleted_at: nil, os_vendor: "Linux", nickname: "Router", vendor: "Buffalo", os: "DD-WRT v24-sp2 (Linux 2.6.24)", ignore_date: "2016-05-30 00:56:45", ignore_flag: false&gt;,
   #&lt;NetworkHost id: 41, location_id: 14, mac_address: "54:9F:13:2A:29:16", ip_address: "10.10.10.133", hostname: "TravisFrsiPhone", created_at: "2015-03-05 18:00:18", updated_at: "2016-04-22 16:11:33", deleted_at: nil, os_vendor: "Unknown", nickname: nil, vendor: "Unknown", os: "Unknown", ignore_date: nil, ignore_flag: false&gt;]</code></pre>
  </div>
  </div>
  </p>