class SynonymScrapper::SynonymScrapper

SynonymScrapper holds the synonym sources to be used and allows making requests to each of these dictionaries by their symbol.

Public Instance Methods

dictionary_exists?(dictionary) click to toggle source

Checks if the given dictionary symbol is a key in the synonym_dictionaries class variable

# File lib/synonym_scrapper.rb, line 79
def dictionary_exists? dictionary
  synonym_dictionaries.key?(dictionary.capitalize)
end
synonym_dictionaries() click to toggle source

Getter for the synonym_dictionaries class variable

# File lib/synonym_scrapper.rb, line 55
def synonym_dictionaries
  @@synonym_dictionaries
end
synonyms(word, dictionary) click to toggle source

Request the synonyms of a word from the selected dictionary.

A request to all dictionaries available can be made by iterating over the keys in class variable synonym_dictionaries

A DictionaryNotAvailable is raised if a wrong dictionary key is given. A WordFormatError is raised if word is not a string.

# File lib/synonym_scrapper.rb, line 68
def synonyms word, dictionary
  raise DictionaryNotAvailable, dictionary unless dictionary_exists?(dictionary)
  raise WordFormatError, word unless word.is_a? String

  return synonym_dictionaries[dictionary.capitalize].synonyms(word)
end