diff --git a/app.rb b/app.rb index a5f63e4..b6d5885 100644 --- a/app.rb +++ b/app.rb @@ -5,8 +5,9 @@ require './environments' set :public_folder, 'public' +# CONTROLLER get '/' do - @raids = Raid.all + @raids = Raid.all.reverse erb :index end @@ -24,6 +25,28 @@ post '/' do end end +#HELPERS +def readable_number(value) + numbers.each do |number, symbol| + if value.to_f / number.to_f > 1 + return (value.to_f / number.to_f).to_s + symbol + end + end + + return value +end + +def numbers + { + '1000000000000000' => 'Q', + '1000000000000' => 'T', + '1000000000' => 'B', + '1000000' => 'M', + '1000' => 'K' + } +end + +# MODEL class Raid < ActiveRecord::Base def money=(value) value = value.to_s.gsub(/[$,]/, '').to_f diff --git a/views/index.erb b/views/index.erb index 59ea911..09222c6 100644 --- a/views/index.erb +++ b/views/index.erb @@ -1,6 +1,6 @@

Index

- +
@@ -15,8 +15,8 @@ - - + + <% end %> diff --git a/views/layout.erb b/views/layout.erb index 5bea7b0..90da949 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -1,10 +1,23 @@ - + + + + + Raids + -<%= yield %> +
+ + + <%= yield %> +
Attacker
<%= raid.attacker %> <%= raid.defender %><%= raid.soldiers.to_f / 1000000000000.0 %>T<%= raid.money.to_f / 1000000000000.0 %>T<%= readable_number(raid.soldiers) %><%= readable_number(raid.money) %> <%= raid.created_at %>