Class: ProxiesScanner::ProxyFormater

Inherits:
Object
  • Object
show all
Defined in:
lib/proxies-scanner/proxy.rb

Constant Summary collapse

SEPARATOR =
'   '
COL_IP_SIZE =
'255.255.255.255'.size
COL_PORT_SIZE =
'99999'.size
COL_STATUS_SIZE =
Proxy::STATUS_STR_MAX_LENGTH

Class Method Summary collapse

Class Method Details

.fetch(proxy) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/proxies-scanner/proxy.rb', line 72

def self.fetch(proxy)
  s_color = "\033[31m"
  s_color = "\033[32m" if proxy.status == Proxy::STATUS_OPEN
  s_color = "\033[35m" if proxy.status == Proxy::STATUS_FILTERED
  s_color = "\033[33m" if proxy.status == Proxy::STATUS_TIMEOUT

  s_time = ""
  s_time = "response-time: #{(proxy.response_time.round(2)).to_s[0..8].rjust(9)} (ms)" if proxy.response_time > 0
  "%color #{proxy.ip.rjust(COL_IP_SIZE)}#{SEPARATOR}#{proxy.port.to_s.ljust(COL_PORT_SIZE)}#{SEPARATOR}[#{proxy.area.upcase}]#{SEPARATOR}[#{proxy.status.center(COL_STATUS_SIZE)}]#{SEPARATOR}#{s_time}\033[0m\n".gsub(/%color/, s_color)
end