require "roda"
require_relative "rank_king"
module RankKing
class Web < Roda
plugin :named_templates
plugin :render
template(:layout) { <<~ERB }
Rank King
<%= yield %>
ERB
template(:pools) { <<~ERB }
Pools
ERB
template(:pool) { <<~ERB }
<%= @pool.name %>
Axes
Items
<% @pool.items.each do |item| %>
- <%= item.title %>
<% end %>
ERB
template(:axis) { <<~ERB }
<%= @axis.pool.name %> - <%= @axis.name %>
Items
<% @axis.ratings.sort_by { -_1.ordinal }.each.with_index do |rating, i| %>
<%= i+1 %> |
<%= rating.item.title %> |
<%= rating.ordinal.round(1) %> |
<%= rating.mu.round(1) %> |
<%= rating.sigma.round(1) %> |
<% end %>
ERB
route do |r|
r.root do
r.redirect "/pools"
end
r.on "pools" do
r.is do
@pools = Pool.all
view :pools
end
r.on Integer do |id|
@pool = Pool[id]
r.is do
view :pool
end
r.on "axes" do
r.is Integer do |id|
@axis = Axis[id]
view :axis
end
end
end
end
end
end
end