Reduce to first_negative
This commit is contained in:
parent
1a4991aef1
commit
6f822f5706
3 changed files with 0 additions and 32 deletions
8
app.rb
8
app.rb
|
@ -32,16 +32,8 @@ post '/' do
|
|||
end
|
||||
|
||||
get '/bossfight' do
|
||||
puts "RAIDS FOR MAFIAMAN"
|
||||
user_raids = Raid.for_user('mafiaman')
|
||||
puts "FIRST NEGATIVE"
|
||||
@first_negative = user_raids.first_negative
|
||||
unless @first_negative == nil
|
||||
puts "SOLDIERS LOST"
|
||||
@soldiers_lost_to_date = user_raids.to_date(@first_negative.created_at).soldiers_lost
|
||||
puts "SOLDIERS BY ATTACKER"
|
||||
@soldiers_by_attacker = user_raids.to-date(@first_negative.created_at).by_attacker.soldiers_lost
|
||||
end
|
||||
|
||||
erb :bossfight
|
||||
end
|
||||
|
|
|
@ -16,16 +16,4 @@ class Raid < ActiveRecord::Base
|
|||
def self.first_negative
|
||||
where('money < 0').order(:created_at).first
|
||||
end
|
||||
|
||||
def self.to_date(date)
|
||||
where('created_at < ?', date)
|
||||
end
|
||||
|
||||
def self.soldiers_lost
|
||||
sum(:soldiers)
|
||||
end
|
||||
|
||||
def self.by_attacker
|
||||
group(:attacker)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,3 @@
|
|||
<% if @first_negative %>
|
||||
Raider who broke the walls: <%= @first_negative.attacker %><br/>
|
||||
<%end%>
|
||||
|
||||
<% if @soldiers_lost_to_date %>
|
||||
Soldiers defeated: <%= @soldiers_lost_to_date %><br/>
|
||||
<%end%>
|
||||
|
||||
<% require 'pp' %>
|
||||
<% if @soldiers_by_attacker %>
|
||||
Participants:
|
||||
<% @soldiers_by_attacker.each do |raid| %>
|
||||
<% pp raid %>
|
||||
<%end%>
|
||||
<%end%>
|
||||
|
|
Loading…
Reference in a new issue