Class: IdiomExplorer
- Inherits:
-
Object
- Object
- IdiomExplorer
- Defined in:
- lib/words_and_idioms/idiom_explorer.rb
Constant Summary collapse
- @@word_url =
"http://www.macmillandictionary.com/us/open-dictionary/latestEntries.html"- @@html =
open(@@word_url)
- @@doc =
Nokogiri::HTML(@@html)
- @@all =
[]
Class Method Summary collapse
Class Method Details
.idiom_routine ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/words_and_idioms/idiom_explorer.rb', line 26 def self.idiom_routine IdiomList.new counter = 1 IdiomList.all.each do |hash| hash.each do |k,v| puts "#{counter}. #{k}" counter += 1 end end puts " " puts "Which idiom would you like me to define?" puts " " input = (gets.chomp).to_i puts " " puts "Interesting choice. Here is the definition:".magenta puts " " hash_value = IdiomList.all[input - 1] hash_idiom = hash_value.keys[0] hash_def = hash_value[hash_idiom] puts "#{hash_idiom.upcase.yellow}: #{hash_def}" puts " " puts " " puts "Would you like to see this word in context?".light_blue puts "Y/N" context = gets.chomp.downcase if context == "y" self.usage puts " " puts " " puts @usage_array[input - 1].green puts " " puts " " end end |
.usage ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/words_and_idioms/idiom_explorer.rb', line 12 def self.usage @usage_array = [] counter = 0 @@doc.css(" #openEntries .openEntry .openSense").each do |entry| if @@doc.css(" #openEntries .openEntry .openSense")[counter].children[2] != nil @usage_array << @@doc.css(" #openEntries .openEntry .openSense")[counter].children[1].text else @usage_array << "Looks like nobody's put an example sentence up yet. Maybe you could submit one!" end counter +=1 end @usage_array end |