Sha256: 95e5205bd9c4c9f3af6542dd64001c915f849b485dd3c4ca3637be04f11841e4
Contents?: true
Size: 1.04 KB
Versions: 11
Compression:
Stored size: 1.04 KB
Contents
module Institutions#:no_doc module IpAddresses#:no_doc require 'ipaddr_range_set' attr_reader :ip_addresses def ip_addresses=(args) args.collect! do |arg| arg.match(/-/) ? convert_to_range(arg) : arg end @ip_addresses = IPAddrRangeSet.new(*args) end protected :ip_addresses= def ip_addresses_add(arg1, arg2) arg1.add(arg2) end protected :ip_addresses_add def convert_to_range(s) s.split("-")[0]...s.split("-")[1] end private :convert_to_range # # Returns a +boolean+ indicating whether the candidate IP # address is in the Institution's IP range. # Example: # # require 'institutions' # institution = Institution.new("my_inst", "My Institution", "ip_addresses" => ["127.0.0.1", 127.0.0.2"]) # data.includes_ip?("127.0.0.1") # => true # data.includes_ip?("127.0.0.3") # => false # def includes_ip?(candidate) return false if ip_addresses.nil? return ip_addresses.include? candidate end end end
Version data entries
11 entries across 11 versions & 1 rubygems