Class: SynonymScrapper::Educalingo
- Defined in:
- lib/synonym_scrapper/educalingo.rb
Overview
Scrapper for Educalingo’s website
Constant Summary
Constants inherited from Scrapper
Instance Attribute Summary
Attributes inherited from Scrapper
#base_url, #max_retries, #retries_left
Instance Method Summary collapse
-
#build_call_url(word) ⇒ Object
Build the url to be called using this class’
base_urland aword. -
#initialize ⇒ Educalingo
constructor
Initialize the parent Scrapper Class.
-
#synonyms(word, options = {}) ⇒ Object
Obtain synonyms of a
wordfrom Educalingo.
Methods inherited from Scrapper
Constructor Details
#initialize ⇒ Educalingo
Initialize the parent Scrapper Class
14 15 16 |
# File 'lib/synonym_scrapper/educalingo.rb', line 14 def initialize() super(5, "https://educalingo.com/en/dic-es/") end |
Instance Method Details
#build_call_url(word) ⇒ Object
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.
22 23 24 |
# File 'lib/synonym_scrapper/educalingo.rb', line 22 def build_call_url(word) URI.parse(URI.escape(base_url + word)) end |
#synonyms(word, options = {}) ⇒ Object
Obtain synonyms of a word from Educalingo.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/synonym_scrapper/educalingo.rb', line 29 def synonyms(word, = {}) 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 |