### Home Classes Methods

### In Files

- lib/rbot/maskdb.rb

### Parent

Object

### Namespace

- CLASS Irc::NetmaskDb::Tree

### Methods

- ::new
- #add
- #cook_component
- #find
- #mask2keys
- #metric
- #remove

### Class/Module Index

Quicksearch

- Irc
- Irc::AsciiCasemap
- Irc::BanlistMessage
- Irc::BasicUserMessage
- Irc::Bot
- Irc::Bot::Auth
- Irc::Bot::Auth::BotOwnerClass
- Irc::Bot::Auth::BotUser
- Irc::Bot::Auth::Command
- Irc::Bot::Auth::DefaultBotUserClass
- Irc::Bot::Auth::InvalidPassword
- Irc::Bot::Auth::ManagerClass
- Irc::Bot::Auth::PermissionSet
- Irc::Bot::Config
- Irc::Bot::Config::ArrayValue
- Irc::Bot::Config::BooleanValue
- Irc::Bot::Config::EnumValue
- Irc::Bot::Config::FloatValue
- Irc::Bot::Config::IntegerValue
- Irc::Bot::Config::ManagerClass
- Irc::Bot::Config::StringValue
- Irc::Bot::Config::Value
- Irc::Bot::Config::Wizard
- Irc::Bot::DataFilter
- Irc::Bot::DataStream
- Irc::Bot::Language
- Irc::Bot::MessageMapper
- Irc::Bot::MessageMapper::Failure
- Irc::Bot::MessageMapper::FriendlyFailure
- Irc::Bot::MessageMapper::NoActionFailure
- Irc::Bot::MessageMapper::NoMatchFailure
- Irc::Bot::MessageMapper::NotPrivateFailure
- Irc::Bot::MessageMapper::NotPublicFailure
- Irc::Bot::MessageMapper::PartialMatchFailure
- Irc::Bot::MessageParameter
- Irc::Bot::MessageTemplate
- Irc::Bot::Plugins
- Irc::Bot::Plugins::BotModule
- Irc::Bot::Plugins::CoreBotModule
- Irc::Bot::Plugins::Plugin
- Irc::Bot::Plugins::PluginManagerClass
- Irc::Bot::Plugins::RecurseTooDeep
- Irc::Bot::Plugins::RemoteBotModule
- Irc::Bot::Plugins::RemoteCoreBotModule
- Irc::Bot::Plugins::RemotePlugin
- Irc::Bot::Registry
- Irc::Bot::Registry::Accessor
- Irc::Bot::RemoteDispatcher
- Irc::Bot::RemoteMessage
- Irc::Bot::RemoteObject
- Irc::Bot::Wordlist
- Irc::BotConfig
- Irc::Casemap
- Irc::Channel
- Irc::Channel::Mode
- Irc::Channel::ModeHash
- Irc::Channel::ModeTypeA
- Irc::Channel::ModeTypeB
- Irc::Channel::ModeTypeC
- Irc::Channel::ModeTypeD
- Irc::Channel::Topic
- Irc::Channel::UserMode
- Irc::ChannelList
- Irc::Client
- Irc::DBHash
- Irc::DBTree
- Irc::InviteMessage
- Irc::JoinMessage
- Irc::KickMessage
- Irc::MessageQueue
- Irc::ModeChangeMessage
- Irc::MotdMessage
- Irc::NamesMessage
- Irc::Netmask
- Irc::NetmaskDb
- Irc::NetmaskDb::Tree
- Irc::NetmaskList
- Irc::NickMessage
- Irc::NoSuchTargetMessage
- Irc::NoticeMessage
- Irc::PartMessage
- Irc::PrivMessage
- Irc::QueueRing
- Irc::QuitMessage
- Irc::RfcCasemap
- Irc::Server
- Irc::ServerOrCasemap
- Irc::Socket
- Irc::Socket::IdentityFilter
- Irc::StrictRfcCasemap
- Irc::TopicMessage
- Irc::UnknownMessage
- Irc::User
- Irc::UserList
- Irc::UserMessage
- Irc::Utils
- Irc::Utils::HttpUtil
- Irc::Utils::HttpUtil::CachedObject
- Irc::Utils::ParseTime
- Irc::WelcomeMessage
- Irc::WhoisMessage
- BDB
- BDB::CIBtree
- MonitorMixin
- MonitorMixin::ConditionVariable
- Net
- Net::HTTPResponse
- Regexp
- Regexp::Irc
- Singleton
- Singleton::SingletonClassMethods
- Timer
- Timer::Action
- TokyoCabinet
- TokyoCabinet::CIBDB
- UnicodePlugin
- UnicodePlugin::UnicodeFilter
- Array
- ArrayOf
- AuthModule
- BasicsModule
- ConditionVariable
- ConfigModule
- DottedIndex
- Enumerable
- Exception
- FiltersModule
- GetText
- GetTextVersionError
- HttpUtilPlugin
- IrcLogModule
- Module
- Numeric
- Object
- Range
- RemoteModule
- ServerError
- String
- Symbol
- UserDataModule
- WordlistModule
- YAML

No matching classes.

# Irc::NetmaskDb

### Public Class Methods

new() click to toggle source

api wrapper for netmasks

    # File lib/rbot/maskdb.rb, line 101
    def initialize
      @tree = Tree.new
    end

### Public Instance Methods

add(user, *masks) click to toggle source

    # File lib/rbot/maskdb.rb, line 126
    def add(user, *masks)
      masks.each do |m|
        debug "adding user #{user} with mask #{m.fullform}"
        @tree.add([user, m], *mask2keys(m))
      end
    end

cook_component(str) click to toggle source

    # File lib/rbot/maskdb.rb, line 105
    def cook_component(str)
      s = (str && !str.empty?) ? str : '*'
      l = s.index(/[\?\*]/)
      if l
        l2 = s.size - s.rindex(/[\?\*]/) - 1
        if l2 > l
          s = s.reverse
          l = l2
        end

        return (l > 0) ? s.slice(0 .. (l - 1)) : ''
      else
        return s
      end
    end

find(iu) click to toggle source

    # File lib/rbot/maskdb.rb, line 149
    def find(iu)
      debug "find(#{iu.fullform})"
      iud = iu.downcased
      matches = @tree.find(iud.host, iud.user, iud.nick).uniq.map do |val|
        m = metric(iu, *val)
        m ? [val[0], m] : nil
      end.compact.sort { |a, b| a[1] <=> a[1] }
      debug "matches: " + (matches.map do |m|
        "#{m[0].username}: [#{m[1]}]"
      end.join(', '))
      return matches.empty? ? nil : matches[0][0]
    end

mask2keys(m) click to toggle source

    # File lib/rbot/maskdb.rb, line 121
    def mask2keys(m)
      md = m.downcased
      [md.host, md.user, md.nick].map { |c| cook_component(c) }
    end

metric(iu, bu, mask) click to toggle source

    # File lib/rbot/maskdb.rb, line 140
    def metric(iu, bu, mask)
      ret = nil
      if iu.matches? mask
        ret = iu.fullform.length - mask.fullform.length
        ret += 10 if bu.transient?
      end
      return ret
    end

remove(user, mask) click to toggle source

    # File lib/rbot/maskdb.rb, line 133
    def remove(user, mask)
      debug "trying to remove user #{user} with mask #{mask}"
      @tree.remove(*mask2keys(mask)) do |val|
        val[0] == user and val[1].fullform == mask.fullform
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.