Class: Matchers::IPMatcher
Instance Attribute Summary collapse
-
#trie ⇒ Object
readonly
Returns the value of attribute trie.
Instance Method Summary collapse
-
#initialize(patterns) ⇒ IPMatcher
constructor
A new instance of IPMatcher.
- #matches?(text) ⇒ Boolean
Constructor Details
#initialize(patterns) ⇒ IPMatcher
Returns a new instance of IPMatcher.
31 32 33 34 |
# File 'lib/matcher.rb', line 31 def initialize(patterns) patterns = (patterns || []).compact.reject(&:empty?).map { |ip| IP.new(ip) }.map(&:to_binary) @trie = Trie.new patterns end |
Instance Attribute Details
#trie ⇒ Object (readonly)
Returns the value of attribute trie.
27 28 29 |
# File 'lib/matcher.rb', line 27 def trie @trie end |
Instance Method Details
#matches?(text) ⇒ Boolean
36 37 38 39 40 41 |
# File 'lib/matcher.rb', line 36 def matches?(text) return false if text.nil? ip = IPAddr.new(text).to_i.to_s(2).rjust(32, '0') trie.forward_match(ip) end |