Class: Wordnik

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/wordnik.rb

Constant Summary

PARTS_OF_SPEECH =
[:noun, :verb, :adjective, :adverb, :idiom, :article, :abbreviation,
:preposition, :prefix, :interjection, :suffix, :verb-transitive", :verb-intransitive"]

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Wordnik) initialize(api_key = nil)



13
14
15
16
17
18
# File 'lib/wordnik.rb', line 13

def initialize(api_key = nil)
  @api_key = (api_key || File.read('.api-key').strip || '').dup
  unless @api_key.blank?
    self.class.default_params :api_key => @api_key
  end
end

Instance Attribute Details

- (Object) api_key

Returns the value of attribute api_key



9
10
11
# File 'lib/wordnik.rb', line 9

def api_key
  @api_key
end

Instance Method Details

- (Object) autocomplete(word_fragment, count = 100)



46
47
48
# File 'lib/wordnik.rb', line 46

def autocomplete(word_fragment, count = 100)
  do_request("suggest.json/#{word_fragment.downcase}", :count => count)
end

- (Object) define(word, *args)



30
31
32
33
34
35
36
# File 'lib/wordnik.rb', line 30

def define(word, *args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  unless options.key?(:count)
    options[:count] = args.any? ? args.first.to_i : 100
  end
  do_request("word.json/#{word.downcase}/definitions", options)
end

- (Object) examples(word)



42
43
44
# File 'lib/wordnik.rb', line 42

def examples(word)
  do_request("word.json/#{word.downcase}/examples")
end

- (Object) frequency(word)



38
39
40
# File 'lib/wordnik.rb', line 38

def frequency(word)
  do_request("word.json/#{word.downcase}/frequency")
end

- (Object) lookup(word)



26
27
28
# File 'lib/wordnik.rb', line 26

def lookup(word)
  do_request("word.json/#{word.downcase}")
end

- (Object) punctuation(word)



62
63
64
# File 'lib/wordnik.rb', line 62

def punctuation(word)
  do_request("word.json/#{word.downcase}/punctuationFactor")
end

- (Object) random(has_definition = true, limit = 1)



54
55
56
57
58
59
60
# File 'lib/wordnik.rb', line 54

def random(has_definition = true, limit = 1)
  if limit == 1
    do_request("words.json/randomWord", :hasDictionaryDef => has_definition)
  else
    do_request("words.json/randomWords", {:hasDictionaryDef => has_definition, :limit => limit})
  end
end

- (Object) word_of_the_day



50
51
52
# File 'lib/wordnik.rb', line 50

def word_of_the_day
  do_request("wordoftheday.json")
end