Class: Slang
- Inherits:
-
Object
- Object
- Slang
- Defined in:
- lib/slang.rb
Instance Attribute Summary collapse
-
#author ⇒ String
readonly
The author of the definition.
-
#definition ⇒ String
readonly
The actual definition.
-
#downvotes ⇒ Integer
readonly
The number of thumbs-down the definition has received.
-
#example ⇒ String
readonly
An example of the word’s usage.
-
#id ⇒ Integer
readonly
The UrbanDictionary definition ID.
-
#permalink ⇒ String
readonly
A permalink to the definition.
-
#upvotes ⇒ Integer
readonly
The number of thumbs-up the definition has received.
-
#word ⇒ String
readonly
The word being defined.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Slang
constructor
Creates a new Slang object.
-
#to_h ⇒ Hash<Symbol, Integer/String>
Returns a hash representation of this Slang object.
Constructor Details
#initialize(opts = {}) ⇒ Slang
Creates a new Slang object.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/slang.rb', line 36 def initialize(opts = {}) @id = opts['defid'] || opts[:defid] @word = opts['word'] || opts[:word] @author = opts['author'] || opts[:author] @permalink = opts['permalink'] || opts[:permalink] @definition = opts['definition'] || opts[:definition] @example = opts['example'] || opts[:example] @upvotes = opts['thumbs_up'] || opts[:thumbs_up] @downvotes = opts['thumbs_down'] || opts[:thumbs_down] end |
Instance Attribute Details
#author ⇒ String (readonly)
Returns The author of the definition.
9 10 11 |
# File 'lib/slang.rb', line 9 def @author end |
#definition ⇒ String (readonly)
Returns The actual definition.
15 16 17 |
# File 'lib/slang.rb', line 15 def definition @definition end |
#downvotes ⇒ Integer (readonly)
Returns The number of thumbs-down the definition has received.
24 25 26 |
# File 'lib/slang.rb', line 24 def downvotes @downvotes end |
#example ⇒ String (readonly)
Returns An example of the word’s usage.
18 19 20 |
# File 'lib/slang.rb', line 18 def example @example end |
#id ⇒ Integer (readonly)
Returns The UrbanDictionary definition ID.
3 4 5 |
# File 'lib/slang.rb', line 3 def id @id end |
#permalink ⇒ String (readonly)
Returns A permalink to the definition.
12 13 14 |
# File 'lib/slang.rb', line 12 def permalink @permalink end |
#upvotes ⇒ Integer (readonly)
Returns The number of thumbs-up the definition has received.
21 22 23 |
# File 'lib/slang.rb', line 21 def upvotes @upvotes end |
#word ⇒ String (readonly)
Returns The word being defined.
6 7 8 |
# File 'lib/slang.rb', line 6 def word @word end |
Instance Method Details
#to_h ⇒ Hash<Symbol, Integer/String>
Returns a hash representation of this Slang object.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/slang.rb', line 49 def to_h { id: @id, word: @word, author: @author, permalink: @permalink, definition: @definition, example: @example, upvotes: @upvotes, downvotes: @downvotes } end |