Class NextwordController
In: app/controllers/nextword_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

[Source]

    # File app/controllers/nextword_controller.rb, line 39
39:         def extras
40:                 @display=get_text
41:         end

file_choices? true if choices are static

[Source]

    # File app/controllers/nextword_controller.rb, line 26
26:   def filechoices?
27:                 false
28:         end

first_time contains initialization code

[Source]

   # File app/controllers/nextword_controller.rb, line 3
3:   def first_time
4:                 session[:choices]=nil
5:                 redirect_to :action=>"index"
6:   end

extras allows instance variables to be displayed to be initialized

[Source]

    # File app/controllers/nextword_controller.rb, line 36
36:         def get_title
37:                 "nextword suggestion"
38:         end

selected processes the string str that the user has selected

[Source]

    # File app/controllers/nextword_controller.rb, line 31
31:         def selected str
32:                 session[:text]=get_text.strip+" #{str} "
33:         end

start_choices must return an array of strings

[Source]

    # File app/controllers/nextword_controller.rb, line 8
 8:   def start_choices
 9:                 @text=get_text.strip
10:                 lw=last_word(@text)
11:                 if lw.empty?
12:                 # suggestions for first word
13:                         nw=Giver.new.get_starting_words(SentencesDir)
14:                 else
15:                         rx=Regexp.new(lw,Regexp::IGNORECASE)
16:                         g=Giver.new
17:                         ac=g.get_matching_sentences(SentencesDir,rx)
18:                         nw=ac.grep(%r{\b#{lw} (\w+)}) do
19:                                 $1
20:                         end
21:                 end
22:                 logger.info "suggested #{nw}"
23:                 nw
24:   end

[Validate]