Class: Cinch::Plugins::Haiku

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/haiku.rb

Instance Method Summary collapse

Instance Method Details

#execute(m) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cinch/plugins/haiku.rb', line 10

def execute(m)
  html = Nokogiri::HTML(open("http://www.dailyhaiku.org/haiku/?pg=#{rand(220) + 1}"))
  haikus = html.search('p.haiku').to_a
  haiku_lines = haikus.sample.text.split(/[\r\n]+/)

  width = haiku_lines.inject(0) { |max, line|
    [line.length, max].max
  }

  haiku_lines.each do |line|
    sleep config[:delay] if config[:delay]
    m.reply('     ' + line.center(width))
  end
end