Permalink
Browse files

word search test

  • Loading branch information...
1 parent 2c49628 commit 72838ddbc8b70533701639cce7b7d6e460be77d0 mdobrota committed Mar 12, 2012
@@ -0,0 +1,18 @@
+class WordSearchTestsController < ApplicationController
+ def new
+ @word_search_test = WordSearchTest.setup_for(current_user)
+ end
+
+ def create
+ @word_search_test = WordSearchTest.new(params[:word_search_test])
+ if @word_search_test.save
+ redirect_to @word_search_test, notice: "Your score is #{@word_search_test.score}"
+ else
+ render action: "new"
+ end
+ end
+
+ def show
+ @word_search_test = WordSearchTest.find(params[:id])
+ end
+end
View
@@ -1,10 +1,18 @@
class Content < ActiveRecord::Base
has_many :questions, :dependent => :delete_all
+ def word_count
+ body.scan(/\b/).size / 2
+ end
+
class << self
def for_reading_speed_test
first
end
+
+ def for_find_the_word_test
+ first
+ end
end
end
@@ -0,0 +1,22 @@
+class WordSearchTest < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :content
+
+ attr_accessor :word
+
+ def pick_a_word!
+ words = content.body.split(/\b/).select {|w| w =~ /\w/}
+ @word = words[rand(words.size)].downcase
+ end
+
+ class << self
+ def setup_for(test_taker)
+ res = new(
+ :user => test_taker,
+ :content => Content.for_find_the_word_test
+ )
+ res.pick_a_word!
+ res
+ end
+ end
+end
@@ -15,7 +15,7 @@
%li= link_to 'Flashing Numbers'
%li= link_to 'Flashing Dots'
%li= link_to 'Scrambled Words'
- %li= link_to 'Find the Word'
+ %li= link_to 'Word Search', new_word_search_test_path
%li= link_to 'Answer the Question'
%li= link_to 'Synonyms/Antonyms'
#content
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,58 @@
+This test will measure your ability to find words in the text.
+= "The word is \"#{@word_search_test.word}\"."
+Click the start button when you are ready and the text will appear below. Click on the word when you find it.
+%button#start_reading Start
+#reading_text
+ = @word_search_test.content.body.gsub(/\b\w+\b/, '<span class="clickable">\0</span>').html_safe
+%div
+
+= form_for(@word_search_test) do |f|
+ = f.hidden_field :content_id
+ = f.hidden_field :user_id
+ = f.hidden_field :score
+
+:javascript
+ $('#start_reading').click(function() {
+ var text_container = $('#reading_text')
+ text_container.show();
+ window.start_time = new Date();
+ });
+
+ $('.clickable').click(function(e) {
+ var clicked_text = $(this).text();
+ var is_correct = clicked_text == "#{@word_search_test.word}";
+ if (is_correct) {
+ var end_time = new Date();
+ var elapsed_time = (end_time - window.start_time) / 1000;
+ var score = Math.round("#{@word_search_test.content.word_count}" * 100 / elapsed_time);
+ $('#word_search_test_score').val(score);
+ alert("Good job! It took you " + elapsed_time + " seconds! There was #{@word_search_test.content.word_count} words in this text. Your score is " + score);
+ $('#new_word_search_test').submit();
+ } else {
+ alert("Try again");
+ }
+ });
+
+ // $('#reading_text').click(function(e) {
+ // s = window.getSelection();
+ // var range = s.getRangeAt(0);
+ // var node = s.anchorNode;
+ // while (range.toString().indexOf(' ') != 0) {
+ // range.setStart(node, (range.startOffset - 1));
+ // }
+ // range.setStart(node, range.startOffset + 1);
+ // do {
+ // range.setEnd(node, range.endOffset + 1);
+ // } while (range.toString().indexOf(' ') == -1 && range.toString().trim() != '');
+ // var str = range.toString().trim();
+ // alert(str);
+ // });
+
+ // $('#finished_reading').click(function() {
+ // var end_time = new Date();
+ // var word_count = count_words($('#reading_text').text());
+ // var elapsed_time_in_seconds = (end_time - window.start_time) / 1000;
+ // var reading_speed = Math.round(word_count * 60 / elapsed_time_in_seconds);
+ // $('#reading_speed_test_wpm').val(reading_speed);
+ // $('#new_reading_speed_test').submit();
+ // });
@@ -0,0 +1,4 @@
+%b Word Search Test Info
+%p
+ %b Score:
+ = @word_search_test.score
View
@@ -1,11 +1,15 @@
SpeedReading::Application.routes.draw do
+
resources :contents do
resources :questions
end
+
resources :reading_speed_tests, :only => [:new, :create, :show] do
resources :comprehension_tests
end
+ resources :word_search_tests, :only => [:new, :create, :show]
+
devise_for :users
root :to => 'home#index'
@@ -0,0 +1,14 @@
+class CreateWordSearchTests < ActiveRecord::Migration
+ def change
+ create_table :word_search_tests do |t|
+ t.integer :content_id
+ t.integer :user_id
+ t.integer :score
+
+ t.timestamps
+ end
+
+ add_index :word_search_tests, :content_id
+ add_index :word_search_tests, :user_id
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120305013545) do
+ActiveRecord::Schema.define(:version => 20120305231200) do
create_table "contents", :force => true do |t|
t.text "body"
@@ -62,4 +62,15 @@
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
+ create_table "word_search_tests", :force => true do |t|
+ t.integer "content_id"
+ t.integer "user_id"
+ t.integer "score"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "word_search_tests", ["content_id"], :name => "index_word_search_tests_on_content_id"
+ add_index "word_search_tests", ["user_id"], :name => "index_word_search_tests_on_user_id"
+
end

0 comments on commit 72838dd

Please sign in to comment.