Class | WordsController |
In: |
app/controllers/words_controller.rb
|
Parent: | ApplicationController |
toggles session[:toggle]
# File app/controllers/words_controller.rb, line 49 49: def backspace 50: session[:toggle]= session[:toggle]? nil:1 51: session[:choices]= nil 52: redirect_to :action => "index" 53: end
# File app/controllers/words_controller.rb, line 32 32: def extras 33: # @displayed=rx_str 34: @text=get_text 35: end
# File app/controllers/words_controller.rb, line 29 29: def get_title 30: "replace '#{last_word(get_text)}' with word:" 31: end
the selected word replaces the last word
# File app/controllers/words_controller.rb, line 37 37: def selected(st) 38: @text=get_text.strip 39: if last_word(@text) 40: @text.gsub!(/\w+$/,st) 41: #replace the "regex" with the selected word 42: else 43: @text << " " << st 44: end 45: session[:text]=@text + " " 46: session[:choices]= nil 47: end
depending on the toggle, either all words containing the chars with or without other chars intervening are offered as choices
# File app/controllers/words_controller.rb, line 8 8: def start_choices 9: @text=get_text.strip 10: lw=last_word(@text) 11: if lw.empty? 12: [] 13: else 14: if session[:toggle] 15: rx_str=lw 16: else 17: rx_str=lw.split("").join(".*") 18: end 19: rx=Regexp.new(rx_str,Regexp::IGNORECASE) 20: # logger.info("words rx:"+rx_str) 21: g=Giver.new 22: ac=g.get_matching_words(WordsDir,rx) -[lw] 23: if ac.size > MaxWords 24: ac=ac[0..MaxWords] 25: end 26: ac 27: end 28: end