Class: Descartes::Tangorin

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/descartes/modules/tangorin.rb

Instance Method Summary collapse

Instance Method Details

#execute(m, search) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/descartes/modules/tangorin.rb', line 23

def execute(m, search)
  begin
    page = Nokogiri::HTML open(URI.escape("http://tangorin.com/general/#{search}")).read, nil, 'utf-8'

    romaji = page.at_xpath('//rt').text.chop
    kana = page.at_xpath('//rb').text
    kanji = page.at_xpath('//span[@class="writing"]').text
    meaning = page.at_xpath('//span[@class="eng"]').text
    info = page.at_xpath('//i[@class="d-info"]')

    if info.nil?
      m.reply "[Tangorin] #{kanji} (#{kana} - #{romaji}): #{meaning}"
    else
      info = info.text.chop.downcase.tr("—","")
      m.reply "[Tangorin] #{kanji} (#{kana} - #{romaji}): #{meaning} (#{info})"
    end
  rescue; end
end