class EasypicController < ApplicationController #require 'find' def filechoices? false end def get_title 'select picture to type' end #possible_chars takes as parameters #root_path, the path to the pictures, and #the string that was already_typed. By looking at the picture file names, #it returns what characters might possibly follow, in order of decreasing likelihood def possible_chars(root_path,already_typed) picked=already_typed g=Giver.new loop do pcs=g.get_filename_part(root_path, Regexp.new('images/\w+'+'/('+picked+ '[a-z, ])[\w, ]*\.(JPEG|JPG|GIF|PNG)$',Regexp::IGNORECASE)) logger.info " possible_chars #{pcs.inspect}" case pcs.size when 0 return [picked],picked when 1 #with only one choice, the computer takes it picked=pcs.first else return pcs,picked end end end def start_choices c,d=possible_chars("images",'') # if c.size==1 # session[:displayed]=c.first # end # logger.info "in start_choices, #{c} displayed #{session[:displayed]}" c end def extras @text=get_text # @displayed=get_displayed # @picfile=make_clickable(get_pic_file(@displayed) ) end def selected(str) # logger.info "in selected, str #{str} displayed #{get_displayed}" # r=/#{str}/i # if (get_displayed.length > 0) && get_displayed =~ r # logger.info "selected #{str}" if get_pic_file(str).empty? choices,typed=possible_chars("images",str) logger.info "in selected, typed #{typed} choices #{choices.inspect}" choices else session[:text]= session[:text].strip+' '+ str + ' ' choices=nil end end def backspace session[:choices]=nil what_next end end