Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: otwcode/otwarchive
base: master
...
head fork: CristinaRO/otwarchive
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
43 app/controllers/toys_controller.rb
@@ -0,0 +1,43 @@
+class ToysController < ApplicationController
+ # Enigel's experimental toy; don't refresh too much!
+ def brainhurter
+ if current_user.is_a?(User)
+ @crtUserFandoms = current_user.filters.by_type("Fandom").group(:id) - [Fandom.find_by_name("No Fandom")]
+ @crtUserCharas = current_user.filters.by_type("Character").group(:id)
+
+ if !params[:level].blank? && params[:level].to_s.downcase == "kamikaze"
+ @crtUserSum = (@crtUserFandoms.collect {|f| f.characters.canonical} + @crtUserCharas).flatten.uniq
+ pool = Array.new(@crtUserSum)
+ else
+ pool = Array.new(@crtUserCharas)
+ end
+
+ if @crtUserFandoms.length < 2 || pool.length < 2
+ flash[:error] = "Sorry, you need to have written in at least two different fandoms, at least two different characters!"
+ else
+ if !params[:pairings_count].blank? && ["5","10","15","20"].include?(params[:pairings_count])
+ @pairings = []
+ # while !pool.empty? && !(pool.collect {|c| c.fandoms}.flatten.uniq.sort.to_s == pool[0].fandoms.uniq.sort.to_s) # this is a bad, bad thing to do!
+ params[:pairings_count].to_i.times do
+ character = pool[rand(pool.size)]
+ pool.delete(character)
+ mate = pool[rand(pool.size)]
+ infinite_loop = 0
+ until (mate.fandoms & character.fandoms).empty? || infinite_loop > 100
+ mate = pool[rand(pool.size)]
+ infinite_loop += 1
+ end
+ pairing = {:top => character, :bottom => mate}
+ @pairings << pairing
+ pool.delete(mate)
+ break if pool.size < 2 || pool.collect(&:fandoms).flatten.uniq.size < 2
+ end
+ @pairings = @pairings.flatten unless @pairings.blank?
+ end
+ end
+ else
+ flash[:error] = "Sorry, this functionality is currently only available to registered users!"
+ end
+ end
+
+end
View
37 app/views/toys/brainhurter.html.erb
@@ -0,0 +1,37 @@
+<h2>Roll-your-own Brainhurt Pairing Generator</h2>
+
+<% form_tag "/toys/brainhurter", :method => :post do %>
+ <%= label_tag "level_normal", "Use your written characters" %>
+ <%= radio_button_tag "level", "normal", params[:level] == "normal" || params[:level].blank? %>
+ <br />
+ <%= label_tag "level_kamikaze", "Use all the characters in your written fandoms" %>
+ <%= radio_button_tag "level", "kamikaze", params[:level] == "kamikaze" %>
+ <br />
+ <%= select_tag "pairings_count", options_for_select(["5", "10", "15", "20"], params[:pairings_count]) %>
+ <%= submit_tag 'Gimme!' %>
+<% end %>
+
+<% if !params[:pairings_count].blank? && !@pairings.blank? %>
+ <ul>
+<% @pairings.each do |pairing| %>
+ <li><%= pairing[:top].name %>/<%= pairing[:bottom].name %></li>
+<% end %>
+ </ul>
+<% elsif !params[:pairings_count].blank? && @pairings.blank? %>
+ <p>Sorry, you either don't have enough variety in fandoms and/or characters, or there was some other kind of error.</p>
+<% end %>
+
+<% unless @crtUserFandoms.blank? %>
+<h3>Your Written Fandoms</h3>
+<p><%= @crtUserFandoms.collect(&:name).sort.join(ArchiveConfig.DELIMITER_FOR_OUTPUT) %></p>
+<% end %>
+
+<% unless @crtUserCharas.blank? %>
+<h3>Your Written Characters</h3>
+<p><%= @crtUserCharas.collect(&:name).sort.join(ArchiveConfig.DELIMITER_FOR_OUTPUT) %></p>
+<% end %>
+
+<% unless @crtUserSum.blank? %>
+<h3>Your Maximal Pool of Characters</h3>
+<p><%= @crtUserSum.collect(&:name).sort.join(ArchiveConfig.DELIMITER_FOR_OUTPUT) %></p>
+<% end %>
View
2  config/routes.rb
@@ -426,6 +426,8 @@
end
end
resources :search, :only => :index
+
+ resources :toys, :only => :brainhurter
match 'search' => 'search#index'
match 'support' => 'feedbacks#create', :as => 'feedbacks', :via => [:post]

No commit comments for this range

Something went wrong with that request. Please try again.