Class: DictionaryRB::Word
- Inherits:
-
Object
- Object
- DictionaryRB::Word
- Defined in:
- lib/dictionary-rb/word.rb
Overview
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
Instance Attribute Summary collapse
-
#dictionary ⇒ DictionaryRB::Dictionary
readonly
Gives Reference Dictionary instance object for word.
-
#urban ⇒ DictionaryRB::Urban
readonly
Gives Urban Dictionary instance object for word.
-
#word ⇒ Object
readonly
The associated word.
Instance Method Summary collapse
-
#dictionary_meaning ⇒ String
(also: #meaning)
Gives dictionary meaning for the word.
-
#dictionary_meanings ⇒ Array
(also: #meanings)
Fetches all meanings from Reference Dictionary for the word.
-
#initialize(word) ⇒ Word
constructor
A new instance of Word.
- #to_s ⇒ Object
-
#urban_meaning ⇒ String
Fetches the first meaning from Urban Dictionary for the word.
-
#urban_meanings ⇒ Array
Fetches all meanings from the Urban Dictionary for the word.
Constructor Details
#initialize(word) ⇒ Word
Returns a new instance of Word.
19 20 21 |
# File 'lib/dictionary-rb/word.rb', line 19 def initialize(word) @word = word end |
Instance Attribute Details
#dictionary ⇒ DictionaryRB::Dictionary (readonly)
Gives Reference Dictionary instance object for word
13 14 15 |
# File 'lib/dictionary-rb/word.rb', line 13 def dictionary @dictionary end |
#urban ⇒ DictionaryRB::Urban (readonly)
Gives Urban Dictionary instance object for word
11 12 13 |
# File 'lib/dictionary-rb/word.rb', line 11 def urban @urban end |
#word ⇒ Object (readonly)
The associated word
9 10 11 |
# File 'lib/dictionary-rb/word.rb', line 9 def word @word end |
Instance Method Details
#dictionary_meaning ⇒ String Also known as: meaning
This method will hit the ENDPOINT and will consume some time to generate result
Gives dictionary meaning for the word
39 40 41 42 43 44 45 46 47 48 49 |
# 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 |
#dictionary_meanings ⇒ Array Also known as: meanings
Fetches all meanings from Reference Dictionary for the word. It is greedily evaluated to save computation when #dictionary_meaning is called.
59 60 61 62 63 64 |
# File 'lib/dictionary-rb/word.rb', line 59 def dictionary_meanings if @dictionary_meanings.nil? dictionary_meaning end @dictionary_meanings end |
#to_s ⇒ Object
110 111 112 |
# File 'lib/dictionary-rb/word.rb', line 110 def to_s sprintf("%s", @word) end |
#urban_meaning ⇒ String
This method will hit the ENDPOINT and will consume some time to generate result
Fetches the first meaning from Urban Dictionary for the word.
81 82 83 84 85 86 87 88 89 90 91 |
# 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 |
#urban_meanings ⇒ Array
Fetches all meanings from the Urban Dictionary for the word. It is greedily evaluated when #urban_meaning is called
100 101 102 103 104 105 |
# File 'lib/dictionary-rb/word.rb', line 100 def urban_meanings if @urban_meanings.nil? urban_meaning end @urban_meanings end |