class Nigel::Commands::Flood

Public Class Methods

process(options) click to toggle source
# File lib/nigel/commands/flood.rb, line 4
def self.process(options)

  threads = []

  Google::Search::Image.new(
    query: 'Nigel Thornberry').each_with_index do |image, i|


    if(image.uri.include? '.gif')

      puts "Nigel spotted at #{ image.uri }!"
      
      threads << self.fetch(image.uri, "#{ i }.gif")
    end
  end

  threads.each(&:join)
end

Private Class Methods

fetch(uri, name) click to toggle source
# File lib/nigel/commands/flood.rb, line 25
def self.fetch(uri, name)
  Thread.new do
    File.open(name, "wb") do |saved_file|
      open(uri, 'rb') do |read_file|
        saved_file.write(read_file.read)
      end
    end
  end
end