class DuckSum::Define_Words
Public Class Methods
first_input()
click to toggle source
Plant first word input seed
# File lib/duck_sum.rb, line 9 def self.first_input require "duck_duck_go" require "rqrcode" word_search = File.read("data/input/first_input.txt").strip ddg = DuckDuckGo.new zci = ddg.zeroclickinfo(word_search) open("data/input/first_definition.txt", "w") { |f| f.puts zci.heading f.puts zci.abstract_text f.puts zci.related_topics["_"][0].text } zci_header = zci.heading zci_abstract = zci.abstract_text zci_related_topics = zci.related_topics name = zci.heading qr_name = "#{zci_header}\n#{zci_abstract}" qrcode = RQRCode::QRCode.new(qr_name) # NOTE: showing with default options specified explicitly png = qrcode.as_png( bit_depth: 1, border_modules: 4, color_mode: ChunkyPNG::COLOR_GRAYSCALE, color: 'black', file: nil, fill: 'white', module_px_size: 6, resize_exactly_to: false, resize_gte_to: false, size: 480 ) IO.write("data/non_compound/#{name}.png", png.to_s) end
second_input()
click to toggle source
Plant second word input seed.
# File lib/duck_sum.rb, line 52 def self.second_input require "duck_duck_go" require "rqrcode" word_search = File.read("data/input/second_input.txt").strip ddg = DuckDuckGo.new zci = ddg.zeroclickinfo(word_search) open("data/input/second_definition.txt", "w") { |f| f.puts zci.heading f.puts zci.abstract_text f.puts zci.related_topics["_"][0].text } zci_header = zci.heading zci_abstract = zci.abstract_text zci_related_topics = zci.related_topics name = zci.heading qr_name = "#{zci_header}\n#{zci_abstract}" qrcode = RQRCode::QRCode.new(qr_name) # NOTE: showing with default options specified explicitly png = qrcode.as_png( bit_depth: 1, border_modules: 4, color_mode: ChunkyPNG::COLOR_GRAYSCALE, color: 'black', file: nil, fill: 'white', module_px_size: 6, resize_exactly_to: false, resize_gte_to: false, size: 480 ) IO.write("data/non_compound/#{name}.png", png.to_s) end
sum_of_both()
click to toggle source
Create a QR code that's the sum of both definitions.
# File lib/duck_sum.rb, line 95 def self.sum_of_both require "duck_duck_go" first_file = File.readlines("data/input/first_definition.txt") second_file = File.readlines("data/input/second_definition.txt") puts "\n\n" heading_1 = first_file[0].strip # Header text_abstract_1 = first_file[1].strip # Definition related_topic_1 = first_file[2].strip # Related Topics heading_2 = second_file[0].strip # Header text_abstract_2 = second_file[1].strip # Definition related_topic_2 = second_file[2].strip # Related Topics print "Your first look up is: #{text_abstract_1} #{related_topic_1}\nYour second look up is: #{text_abstract_2} #{related_topic_2}\n\n" new_lookup = "#{heading_1} #{heading_2}" puts new_lookup ddg = DuckDuckGo.new zci = ddg.zeroclickinfo(new_lookup) print "You must be looking for #{new_lookup}: ".strip puts zci.abstract_text compound_name = zci.heading zci_header = zci.heading zci_abstract = zci.abstract_text zci_related_topics = zci.related_topics qr_name = "#{zci_header}\n#{zci_abstract}" qrcode = RQRCode::QRCode.new(qr_name) # NOTE: showing with default options specified explicitly png = qrcode.as_png( bit_depth: 1, border_modules: 4, color_mode: ChunkyPNG::COLOR_GRAYSCALE, color: 'black', file: nil, fill: 'white', module_px_size: 6, resize_exactly_to: false, resize_gte_to: false, size: 480 ) IO.write("data/compound/#{compound_name}.png", png.to_s) sleep(3) end