class SynonymScrapper::Datamuse
Scrapper
for datamuse's API
Public Class Methods
new()
click to toggle source
Initialize the parent Scrapper
Class
Calls superclass method
# File lib/synonym_scrapper/datamuse.rb, line 14 def initialize() super(3, "https://api.datamuse.com/words?v=es&max=40&ml=") 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/datamuse.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 Datamuse
.
# File lib/synonym_scrapper/datamuse.rb, line 29 def synonyms(word, options = {}) response = call(word).read synonyms = Array.new JSON.parse(response).each do |synonym| synonyms.push({ word: synonym["word"], score: synonym["score"] }) end return synonyms end