require 'net/ping' module Janis module Testing def self.connectable?(proxy) host, port = proxy.split(':') return Net::Ping::TCP.new(host, port).ping end def self.filter_results(criteria = [], results) criteria.each do |criterion| # A criterion is a method that returns true or false about a proxy, like #connectable? results.select! { |proxy| Janis::Testing.send(criterion, "#{proxy[:ip]}:#{proxy[:port]}") } end results end end end