Class: IdiomScraper

Inherits:
Object
  • Object
show all
Defined in:
lib/words_and_idioms/idiom_scraper.rb

Constant Summary collapse

@@url =
"http://www.macmillandictionary.com/us/open-dictionary/latestEntries.html"
@@html =
open(@@url)
@@doc =
Nokogiri::HTML(@@html)

Class Method Summary collapse

Class Method Details

.constructorObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/words_and_idioms/idiom_scraper.rb', line 6

def self.constructor
  counter = 0
  @@doc.search(".openEntry").each do |node|
    name = @@doc.search(".openEntry")[counter].css("a").text
    definition = @@doc.search(".openEntry")[counter].css(".openDef").text
      if @@doc.search(".openEntry")[counter].css(".openEx").text != ""
        usage = @@doc.search(".openEntry")[counter].css(".openEx").text
      elsif @@doc.search(".openEntry")[counter].css(".openEx").text == ""
        usage = "It looks like nobody has submitted a sentence yet. Maybe you could write one!"
      end
      Idiom.new(name, definition, usage)
    counter += 1
  end
end