Class: Crowsad::Learn_First_Objects

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

Class Method Summary collapse

Class Method Details

.teach_wordObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/crowsad.rb', line 7

def self.teach_word
  require "duck_duck_go"
  
  old_first_object = File.read("dictionary/first_object.txt")
  
  new_word = File.read("data/input/first_object.txt").strip
  
  ddg = DuckDuckGo.new
  zci = ddg.zeroclickinfo(new_word)

  open("data/output/glossary/#{new_word}.txt", 'w') { |f|
    f.puts zci.heading
    f.puts zci.abstract_text
    f.puts zci.related_topics['_'][0].text
  }
  
  open('dictionary/first_object.txt', 'w') { |f|
    f.puts zci.heading
    
    f.puts old_first_object
  }
end