bdurand/us_geo

View on GitHub
explorer_app/app/views/counties/_table.html.erb

Summary

Maintainability
Test Coverage
<%
  urban_area ||= nil
  zcta ||= nil
  overlap = (urban_area || zcta)
%>

<table class="table table-striped sortable">
  <thead>
    <tr>
      <th>GEOID</th>
      <th>Name</th>
      <% unless defined?(state) && state %>
        <th>State</th>
      <% end %>
      <% unless defined?(core_based_statistical_area) && core_based_statistical_area %>
        <th>Core Based Statistical Area</th>
      <% else %>
        <th>CBSA Position</th>
      <% end %>
      <th>FIPS Class Code</th>

      <%= demographics_headers %>

      <% if overlap %>
        <th class="text-end">Overlap</th>
      <% end %>
    </th>
  </thead>
  <tbody>
    <% counties.each do |county| %>
      <tr>
        <td><%= county.geoid %></td>
        <td><%= link_to county.name, county_path(county, breadcrumb_params) %></td>
        <% unless defined?(state) && state %>
          <td><%= county.state.name %></td>
        <% end %>
        <% if defined?(core_based_statistical_area) && core_based_statistical_area %>
          <td><%= county.central? ? "Central" : "Outlying" %></td>
        <% else %>
          <td>
            <% if county.core_based_statistical_area %>
              <%= link_to county.core_based_statistical_area.name, core_based_statistical_area_path(county.core_based_statistical_area) %>
            <% else %>
              -
            <% end %>
          </td>
        <% end %>
        <td><%= county.fips_class_code %></td>

        <%= demographics_cells(county, round_area: 0) %>

        <% if overlap %>
          <td class="text-end">
            <% if urban_area %>
              <%= overlap_percentage(urban_area, county, :urban_area_counties) %>
            <% elsif zcta %>
              <%= overlap_percentage(zcta, county, :zcta_counties) %>
            <% end %>
          </td>
        <% end %>
      </tr>
    <% end %>
  </tbody>
</table>