class DictionaryRB::Word
Contains the word and offers methods for {Urban} and Reference {Dictionary} Also provides methods like {#meaning}, {#urban_meaning} etc for direct access. Lot of precautions has been taken to prevent repeated call on endpoints
Attributes
Reference Dictionary
instance
Urban
Dictionary
instance
The associated word
Public Class Methods
@param word [String] The word for Dictionary
@example
word = DictionaryRB::Word.new('boast')
# File lib/dictionary-rb/word.rb, line 19 def initialize(word) @word = word end
Public Instance Methods
Gives dictionary meaning for the word @example
word.dictionary_meaning #or word.meaning
@note This method will hit the {Dictionary::PREFIX ENDPOINT} and will consume some time to generate result @return [String] containing meaning from Reference {Dictionary} for the word
# File lib/dictionary-rb/word.rb, line 39 def dictionary_meaning if @dictionary_meaning.nil? @dictionary = Dictionary.new(@word) meanings = @dictionary.meanings if meanings.is_a? Array and not meanings.empty? @dictionary_meanings = meanings @dictionary_meaning = @dictionary.meaning end end @dictionary_meaning end
Fetches all meanings from Reference Dictionary
for the word. It is greedily evaluated to save computation when {#dictionary_meaning} is called. @example
word.dictionary_meanings #or word.meanings
@see dictionary_meaning
@return [Array] array containing the meanings from Reference {Dictionary} for the word
# File lib/dictionary-rb/word.rb, line 59 def dictionary_meanings if @dictionary_meanings.nil? dictionary_meaning end @dictionary_meanings end
# File lib/dictionary-rb/word.rb, line 110 def to_s sprintf("%s", @word) end
Fetches the first meaning from Urban
Dictionary
for the word. @note This method will hit the {Urban::PREFIX ENDPOINT} and will consume some time to generate result @example
word.urban_meaning
@see urban_meanings
@return [String] containing meaning from {Urban} Dictionary
for the word
# File lib/dictionary-rb/word.rb, line 81 def urban_meaning if @urban_meaning.nil? @urban = Urban.new(@word) meanings = @urban.meanings if meanings.is_a?(Array) and not meanings.empty? @urban_meanings = meanings @urban_meaning = @urban.meaning end end @urban_meaning end
Fetches all meanings from the Urban
Dictionary
for the word. It is greedily evaluated when {#urban_meaning} is called @example
word.urban_meanings #=> ['brag', 'lie', 'boaster']
@see urban_meaning
@return [Array] array containing meanings from {Urban} Dictionary
for the word
# File lib/dictionary-rb/word.rb, line 100 def urban_meanings if @urban_meanings.nil? urban_meaning end @urban_meanings end