Add last date and sort
This commit is contained in:
parent
fc388d954c
commit
f96c976120
2 changed files with 9 additions and 7 deletions
12
app.rb
12
app.rb
|
@ -16,21 +16,23 @@ get '/' do
|
|||
highscores = page.search "//table[@id='highscores_table']//tr[@class='clickable']/td[2]"
|
||||
|
||||
require 'pp'
|
||||
@top20 = {}
|
||||
@top20 = []
|
||||
highscores.each do |td_user|
|
||||
user = td_user.text.scan(/[A-Za-z0-9]+/)
|
||||
@top20[user.first] = nil
|
||||
@top20 << { user: user.first, date: nil }
|
||||
end
|
||||
|
||||
@top20.keys.each do |top20|
|
||||
@top20.each_with_index do |hash, i|
|
||||
@raids.each do |raid|
|
||||
if raid.attacker == top20 || raid.defender == top20
|
||||
@top20[top20] = raid.created_at
|
||||
if raid.attacker == hash[:user] || raid.defender == hash[:user]
|
||||
@top20[i][:date] = raid.created_at
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@top20 = @top20.select { |h| h[:date] }.sort_by { |h| h[:date] } + @top20.reject { |h| h[:date] }
|
||||
|
||||
# get last attack for each
|
||||
# order by date
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
<div class="col-md-3">
|
||||
<ul class="list-group">
|
||||
<% @top20.each do |user, last| %>
|
||||
<li class="list-group-item"><%= user %><span class="pull-right"><%= last.strftime('%H:%M on %m-%d-%Y') if last %></li>
|
||||
<% @top20.each do |user| %>
|
||||
<li class="list-group-item"><%= user[:user] %><span class="pull-right"><%= user[:date].strftime('%H:%M on %m-%d-%Y') if user[:date] %></li>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue