Module: BilisimSozlugu

Defined in:
lib/bilisim_sozlugu.rb,
lib/bilisim_sozlugu/version.rb

Constant Summary collapse

URL =
"http://eski.tbd.org.tr/index.php?sayfa=sozluk&mi1&tipi=ara&harf=A&arama=".freeze
CSS_SELECTOR =
"table tbody tr".freeze
VERSION =
"1.3.0"

Class Method Summary collapse

Class Method Details

.search(word) ⇒ Object



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

def self.search(word)
  call_url = URL + word
  page     = Nokogiri::HTML(open(call_url))
  rows     = page.css(CSS_SELECTOR)

  if rows.last.text.match("Aranan Kelime")
    puts "Aradığınız kelime bulunamadı."
  else
    words = rows.map { |row| [row.children.first.children.text, row.children.last.text] }
    table = Terminal::Table.new :rows => words.drop(2)
    puts table
  end
end