Class | EasypicController |
In: |
app/controllers/easypic_controller.rb
|
Parent: | ApplicationController |
# File app/controllers/easypic_controller.rb, line 64 64: def backspace 65: session[:choices]=nil 66: session[:picked]='' 67: session[:typed]=nil 68: redirect_to :action => "index" 69: end
# File app/controllers/easypic_controller.rb, line 45 45: def extras 46: @picfile=get_pic_file(get_picked) 47: #used in erb file for passing to image_tag 48: if @choices.empty? #we have finished choosing 49: extn=File.extname(@picfile) 50: @typed=File.basename(@picfile,extn) 51: session[:picfile]=@picfile 52: session[:typed]=@typed 53: #this is now available to other modules 54: else 55: @typed='' 56: end 57: session[:spoken]=nil 58: end
require ‘find‘
# File app/controllers/easypic_controller.rb, line 3 3: def first_time 4: session[:choices]=nil 5: # session[:separator]=',' 6: session[:typed]="" #used to pass on name of finally 7: #selected picture to other modules 8: session[:picked]="" #part file name 9: session[:spoken]='' 10: session[:selected_item]=0 11: redirect_to :action => "index" 12: end
# File app/controllers/easypic_controller.rb, line 19 19: def get_picked 20: session[:picked] ||= "" #what has been picked so far 21: end
# File app/controllers/easypic_controller.rb, line 16 16: def get_title 17: 'picture catalog' 18: 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
# File app/controllers/easypic_controller.rb, line 26 26: def possible_chars(root_path,already_typed) 27: g=Giver.new 28: pcs=g.get_filename_part(root_path, 29: Regexp.new('/('+already_typed+ 30: '.)[\w, ]*\.(JPG|GIF|PNG)$',Regexp::IGNORECASE)) 31: # logger.info " possible_chars #{pcs.inspect}" 32: pcs 33: end
# File app/controllers/easypic_controller.rb, line 59 59: def selected(str) 60: session[:picked]= str 61: session[:choices]=nil 62: end
# File app/controllers/easypic_controller.rb, line 34 34: def start_choices 35: @picked= get_picked #what has been "typed" so far 36: @choices=possible_chars("images",@picked) 37: while @choices.size==1 38: #with only one choice, the computer takes it 39: @picked=@choices.first 40: @choices=possible_chars("images",@picked) 41: end 42: session[:picked]=@picked 43: @choices 44: end