<file_sep># Rack Dictionary

To use this open dictionary.rb with ruby. This will start the WEBrick server which by default is on port 8080.

Then in a browser navigate to localhost:8080/?word=Ruby (or whatever you want to find)

If the word is not found in the dictionary it will tell you so.
<file_sep>require 'rack'

class Dictionary

  def self.call(env)
    request = Rack::Request.new(env)

    if request.params.length == 0
      output = "Welcome to Dictionary"
    else
      dictionary = open("dictionary.txt"){|f| f.read }
      word = request["word"].downcase
      found = false
      output = ''
      dictionary.each_line do |line|
        line.strip!
        if line.downcase.start_with?(word)
          found = true
          output = line
          break
        end
      end
      output = "Word not found" unless found
    end
    [200, {"Content-Type" => "text/html"}, ["#{output}"]]
  end

end

Rack::Handler::WEBrick.run Dictionary
