class MWDictionaryGem::Dictionary
Public Class Methods
new(dict_api_key, thes_api_key = nil)
click to toggle source
Calls superclass method
# File lib/mw-dictionary.rb, line 10 def initialize(dict_api_key, thes_api_key = nil) @cache = Cache.new @client = Client.new(dict_api_key, thes_api_key) @url = "https://www.dictionaryapi.com/api/v3/references" super() end
Public Instance Methods
display(json)
click to toggle source
# File lib/mw-dictionary.rb, line 39 def display(json) @cache.add(@word, @thesaurus, @thesaurus ? parse_thesaurus(json) : parse_dict(json)) end
search(word)
click to toggle source
# File lib/mw-dictionary.rb, line 17 def search(word) thes = nil word, thes = word.split() if thes != nil && thes != '-t' puts "Invalid format (try '-t')." exit(1) end puts "[ #{word} ]" res = @cache.search(word, thes) if res puts res return end @thesaurus = !!thes @word = word url = ((@thesaurus) ? "#{@url}/thesaurus/json/" : "#{@url}/collegiate/json/") + @word response, json = @client.request(url, @thesaurus) display(json) end