Created
October 4, 2016 16:08
-
-
Save jsugarman/59a3db4dca397de7874a845fb7a04700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'netaddr' | |
class IpAddressMatcher | |
def initialize(terms) | |
@cidrs = cidrs(terms) | |
end | |
def ===(other) | |
@cidrs.any? { |cidr| cidr.matches?(other) } | |
end | |
private | |
def cidrs(terms) | |
terms.split(';').map { |s| cidr(s) } | |
end | |
def cidr(term) | |
NetAddr::CIDR.create(term) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment