Created
February 3, 2011 05:23
-
-
Save keithrbennett/809088 to your computer and use it in GitHub Desktop.
WordLookup, for Rick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WordLookup | |
| def run() | |
| lines = File.readlines('words.txt') | |
| File.open('words-with-definitions.txt', 'w') do |output_file| | |
| # assume the only thing on the line is the word | |
| lines.each do |word| | |
| definition = get_definition(word) | |
| output_file << "#{word} - #{definition}\n" | |
| end | |
| end | |
| # This is the hard part, needs some research. | |
| def get_definition(word) | |
| # Ruby's Net::HTTP makes it easy to send HTTP requests and get the | |
| # response, but you need to know what to send (i.e. which site, which | |
| # parameters, how to build the URL with them) and how to parse the | |
| # response, which will probably be an entire web page in HTML, | |
| # Javascript, etc. | |
| end | |
| end | |
| # Instantiate the class and call its run(): | |
| WordLookup.new.run | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment