Class: Lolol::Lulz

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

Instance Method Summary collapse

Constructor Details

#initializeLulz

Returns a new instance of Lulz.



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

def initialize
  @browser = Mechanize.new
end

Instance Method Details

#jokeObject



10
11
12
13
14
15
16
17
# File 'lib/lolol.rb', line 10

def joke
  page = @browser.get('http://jokes.reddit.com')
  jokes = page.links.map { |l| l if l.dom_class == 'title may-blank ' }.compact!
  joke_page = @browser.get(jokes.sample.uri.to_s)
  joke = joke_page.search(".md")[1].text
  title = joke_page.links.map { |j| j if j.dom_class == 'title may-blank ' }.compact![0].text
  "#{title}\n#{joke}"
end