Reduce to first_negative

This commit is contained in:
Andrew Tomaka 2015-04-28 10:14:16 -04:00
parent 1a4991aef1
commit 6f822f5706
3 changed files with 0 additions and 32 deletions

8
app.rb
View file

@ -32,16 +32,8 @@ post '/' do
end end
get '/bossfight' do get '/bossfight' do
puts "RAIDS FOR MAFIAMAN"
user_raids = Raid.for_user('mafiaman') user_raids = Raid.for_user('mafiaman')
puts "FIRST NEGATIVE"
@first_negative = user_raids.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 erb :bossfight
end end

View file

@ -16,16 +16,4 @@ class Raid < ActiveRecord::Base
def self.first_negative def self.first_negative
where('money < 0').order(:created_at).first where('money < 0').order(:created_at).first
end 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 end

View file

@ -1,15 +1,3 @@
<% if @first_negative %> <% if @first_negative %>
Raider who broke the walls: <%= @first_negative.attacker %><br/> Raider who broke the walls: <%= @first_negative.attacker %><br/>
<%end%> <%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%>