Class: Chuck::Joke

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Joke

Returns a new instance of Joke.



5
6
7
# File 'lib/chuck/joke.rb', line 5

def initialize(options = {})
  options.each{|k, v| self.send("#{k}=", v) if respond_to?(k) }
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#categoriesObject

Returns the value of attribute categories.



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

def categories
  @categories
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

Class Method Details

.jokes_from_result(result) ⇒ Object



9
10
11
12
13
# File 'lib/chuck/joke.rb', line 9

def self.jokes_from_result(result)
  result.map do |j| 
    Joke.new body: j['joke'], categories: j['categories'], id: j['id']
  end
end

Instance Method Details

#to_sObject



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

def to_s
  @body
end