Class: Proxtopus::ProxySet

Inherits:
Array
  • Object
show all
Defined in:
lib/proxtopus/proxy_set.rb

Instance Method Summary collapse

Instance Method Details

#include?(proxy) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
# File 'lib/proxtopus/proxy_set.rb', line 39

def include?(proxy)
  if proxy.is_a?(Proxtopus::Proxy)
    each do |p|
      return true if proxy == p
    end
    false
  else
    false
  end
end

#push(proxy) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/proxtopus/proxy_set.rb', line 4

def push(proxy)
  #puts proxy.class
  if !proxy.is_a?(Proxtopus::Proxy) && !proxy.is_a?(Proxtopus::ProxySet) && !proxy.is_a?(Hash)
    raise ArgumentError, "A ProxySet may only contain Proxy, ProxySet, or Hash objects!"
  end
  
  if !proxy.is_a?(Proxtopus::ProxySet)
    if proxy.is_a?(Hash)
      proxy = Proxy.new(proxy['host'], proxy['port'], proxy['protocol'], proxy['country'], proxy['anonymity'])
    end
    
    super(proxy) if !include?(proxy)
  else
    proxy.each { |p| super(p) }
  end
  self
end

#shift(proxy) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/proxtopus/proxy_set.rb', line 22

def shift(proxy)
  if !proxy.is_a?(Proxtopus::Proxy) && !proxy.is_a?(Hash)
    raise ArgumentError, "A ProxySet may only contain Proxy or Hash objects!"
  end
 
  if !proxy.is_a?(Proxtopus::ProxySet) 
    if proxy.is_a?(Hash)
      proxy = Proxy.new(proxy['host'], proxy['port'], proxy['protocol'], proxy['country'], proxy['anonymity'])
    end
    
    super(proxy) if !include?(proxy)
  else
    proxy.each { |p| super(p) }
  end
  self
end