<style>
  #users {width:600px;text-align: center}
  #users thead {line-height:25px; background-color:#1c1b1b; height:25px; color:#d6edff; font-weight:bold;}
  #users tbody {line-height:25px; padding-top:3px; font-weight:bold; }
  #users .index {color:#d6edff}
  #users .me {color:deepskyblue}
  #users .name a {color:#FFE793}
  #users .credits {color:#FF6468}
  #users .ratio {color:#58DB3E;}
  #users .win {color:red;}
  #users .lost {color:blue;}
  #users .show a {color:#DFC84B}
</style>

<table id="users">
  <thead>
    <tr>
      <th><%= User.human_attribute_name :ranking %> </th>
      <th><%= User.human_attribute_name :name %></th>
      <th><%= Duel.human_attribute_name :points %></th>
      <th><%= Duel.human_attribute_name :wins %></th>
      <th><%= Duel.human_attribute_name :losses %></th>
      <th><%= User.human_attribute_name :ratio %></th>
      <th><%= User.human_attribute_name :detail %></th>
    </tr>
  </thead>
  <tbody>
    <% top_users = User.order(:credits).reverse_order.limit(10) %>
    <% if logged? && !top_users.include?(@current_user) %>
      <% top_users << @current_user %>
      <% my_index = User.where("credits>=?", @current_user.credits).count %>
    <% end %>
    <% top_users.each_with_index do |user, index| %>
      <tr>
        <% if user == @current_user %>
          <td class="index me"><%= my_index %></td>
        <% else %>
          <td class="index"><%= index.next %></td>
        <% end %>
        <td class="name"><%= link_to user.name, user %></td>
        <td class="credits"><%= user.credits %></td>
        <% win = user.wins.count %>
        <% all = user.duels.count %>
        <td class="win"><%= win %></td>
        <td class="lost"><%= all - win %></td>
        <td class="ratio"><%= all.zero? ? 0 : 100 * win / all %>%</td>
        <td class="show"><%= link_to User.human_attribute_name(:show), user %></td>
      </tr>
    <% end %>
  </tbody> 
</table>