Class: Lolol::Lulz
- Inherits:
-
Object
- Object
- Lolol::Lulz
- Defined in:
- lib/lolol.rb
Instance Method Summary collapse
-
#initialize ⇒ Lulz
constructor
A new instance of Lulz.
- #joke ⇒ Object
Constructor Details
#initialize ⇒ Lulz
Returns a new instance of Lulz.
6 7 8 |
# File 'lib/lolol.rb', line 6 def initialize @browser = Mechanize.new end |
Instance Method Details
#joke ⇒ Object
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 |