Module: IPAddrList::Algorithm::LinearSearch

Includes:
Lint
Defined in:
lib/ipaddr_list.rb

Overview

slow and simple. It’s for just benchmarking script.

Instance Method Summary collapse

Instance Method Details

#add(ip) ⇒ Object



79
80
81
82
83
84
# File 'lib/ipaddr_list.rb', line 79

def add ip
  unless ip.kind_of? IPAddr
    ip = IPAddr.new(ip.to_s)
  end
  @ip_list.push ip
end

#after_init(ip_list = []) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/ipaddr_list.rb', line 69

def after_init ip_list=[]
  @ip_list = ip_list.map {|item|
    if item.kind_of? IPAddr
      item
    else
      IPAddr.new(item.to_s)
    end
  }
end

#each(&block) ⇒ Object



87
88
89
# File 'lib/ipaddr_list.rb', line 87

def each &block
  @ip_list.each(&block)
end

#include?(ip) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
# File 'lib/ipaddr_list.rb', line 91

def include? ip
  if ip.kind_of? IPAddr
    ipaddr = ip
  else
    ipaddr = IPAddr.new(ip)
  end
  @ip_list.any? {|item| item.include? ipaddr }
end