Sha256: 484a17f1560863d63749c974ec1cf46813972b25e4e4a3017ae9726a5f185284
Contents?: true
Size: 948 Bytes
Versions: 4
Compression:
Stored size: 948 Bytes
Contents
require 'lita/handlers/enhance/node_index' module Lita module Handlers class Enhance class IpEnhancer < Enhancer IP_REGEX = /(?:[0-9]{1,3}\.){3}[0-9]{1,3}/ def initialize(redis) super @nodes_by_ip = NodeIndex.new(redis, 'nodes_by_ip') end def index(ip, node) @nodes_by_ip[ip] = node end def enhance!(string, level) substitutions = [] string.scan(IP_REGEX) do match = Regexp.last_match ip = match.to_s range = (match.begin(0)...match.end(0)) node = @nodes_by_ip[ip] if node new_text = render(node, level) substitutions << Substitution.new(range, new_text) end end substitutions end def to_s "#{self.class.name}: #{@nodes_by_ip.size} IPs indexed" end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems