class SynonymScrapper::Educalingo

Scrapper for Educalingo's website

Public Class Methods

new() click to toggle source

Initialize the parent Scrapper Class

Calls superclass method
# File lib/synonym_scrapper/educalingo.rb, line 14
def initialize()
        super(5, "https://educalingo.com/en/dic-es/")
end

Public Instance Methods

build_call_url(word) click to toggle source

Build the url to be called using this class' base_url and a word. Returns an url to where word's synonyms can be obtained.

# File lib/synonym_scrapper/educalingo.rb, line 22
def build_call_url(word)
        URI.parse(URI.escape(base_url + word))
end
synonyms(word, options = {}) click to toggle source

Obtain synonyms of a word from Educalingo.

# File lib/synonym_scrapper/educalingo.rb, line 29
def synonyms(word, options = {})
        response = call(word)
        doc = Nokogiri.HTML(response)
        synonyms = Array.new
        doc.css('#wordcloud1 > span').each do |synonym|
                score = Integer(synonym.values[0])

                synonyms.push({
                        word: synonym.inner_html,
                        score: score
                }) unless score < 75
                # A minimum score of 75 is considered because educalingo
                # tends to have completely unrelated words around this score
        end

        return synonyms
end