Class: Slang

Inherits:
Object
  • Object
show all
Defined in:
lib/slang.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Slang

Creates a new Slang object.

Parameters:

  • opts (Hash) (defaults to: {})

    The options hash.

Options Hash (opts):

  • :id (Integer)

    The definition ID.

  • :word (String)

    The word being defined.

  • :author (String)

    The author of the definition.

  • :permalink (String)

    The permalink for the definition.

  • :definition (String)

    The definition for the :word

  • :example (String)

    An example of its usage.

  • :thumbs_up (Integer)

    The number of upvotes the definition has received.

  • :thumbs_down (Integer)

    The number of downvotes the definition has received.



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

#authorString (readonly)

Returns The author of the definition.

Returns:

  • (String)

    The author of the definition.



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

def author
  @author
end

#definitionString (readonly)

Returns The actual definition.

Returns:

  • (String)

    The actual definition.



15
16
17
# File 'lib/slang.rb', line 15

def definition
  @definition
end

#downvotesInteger (readonly)

Returns The number of thumbs-down the definition has received.

Returns:

  • (Integer)

    The number of thumbs-down the definition has received.



24
25
26
# File 'lib/slang.rb', line 24

def downvotes
  @downvotes
end

#exampleString (readonly)

Returns An example of the word’s usage.

Returns:

  • (String)

    An example of the word’s usage.



18
19
20
# File 'lib/slang.rb', line 18

def example
  @example
end

#idInteger (readonly)

Returns The UrbanDictionary definition ID.

Returns:

  • (Integer)

    The UrbanDictionary definition ID.



3
4
5
# File 'lib/slang.rb', line 3

def id
  @id
end

Returns A permalink to the definition.

Returns:

  • (String)

    A permalink to the definition.



12
13
14
# File 'lib/slang.rb', line 12

def permalink
  @permalink
end

#upvotesInteger (readonly)

Returns The number of thumbs-up the definition has received.

Returns:

  • (Integer)

    The number of thumbs-up the definition has received.



21
22
23
# File 'lib/slang.rb', line 21

def upvotes
  @upvotes
end

#wordString (readonly)

Returns The word being defined.

Returns:

  • (String)

    The word being defined.



6
7
8
# File 'lib/slang.rb', line 6

def word
  @word
end

Instance Method Details

#to_hHash<Symbol, Integer/String>

Returns a hash representation of this Slang object.

Returns:

  • (Hash<Symbol, Integer/String>)

    See the source for details.



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