Class | Net::IRC::Message::ModeParser |
In: |
lib/net/irc/message/modeparser.rb
|
Parent: | Object |
ONE_PARAM_MASK | = | 0 |
ONE_PARAM | = | 1 |
ONE_PARAM_FOR_POSITIVE | = | 2 |
NO_PARAM | = | 3 |
# File lib/net/irc/message/modeparser.rb, line 8 8: def initialize 9: @modes = {} 10: @op_to_mark_map = {} 11: @mark_to_op_map = {} 12: 13: # Initialize for ircd 2.11 (RFC2812+) 14: set(:CHANMODES, 'beIR,k,l,imnpstaqr') 15: set(:PREFIX, '(ov)@+') 16: end
# File lib/net/irc/message/modeparser.rb, line 18 18: def mark_to_op(mark) 19: mark.empty? ? nil : @mark_to_op_map[mark.to_sym] 20: end
# File lib/net/irc/message/modeparser.rb, line 43 43: def parse(arg) 44: params = arg.kind_of?(Net::IRC::Message) ? arg.to_a : arg.split(" ") 45: params.shift 46: 47: ret = { 48: :positive => [], 49: :negative => [], 50: } 51: 52: current = ret[:positive] 53: until params.empty? 54: s = params.shift 55: s.scan(/./).each do |c| 56: c = c.to_sym 57: case c 58: when :+ 59: current = ret[:positive] 60: when :- 61: current = ret[:negative] 62: else 63: case @modes[c] 64: when ONE_PARAM_MASK,ONE_PARAM 65: current << [c, params.shift] 66: when ONE_PARAM_FOR_POSITIVE 67: if current.equal?(ret[:positive]) 68: current << [c, params.shift] 69: else 70: current << [c, nil] 71: end 72: when NO_PARAM 73: current << [c, nil] 74: else 75: if @op_to_mark_map[c] 76: current << [c, params.shift] 77: end 78: end 79: end 80: end 81: end 82: 83: ret 84: end
# File lib/net/irc/message/modeparser.rb, line 22 22: def set(key, value) 23: case key 24: when :PREFIX 25: if value =~ /\A\(([a-zA-Z]+)\)(.+)\z/ 26: @op_to_mark_map = {} 27: key, value = Regexp.last_match[1], Regexp.last_match[2] 28: key.scan(/./).zip(value.scan(/./)) {|pair| 29: @op_to_mark_map[pair[0].to_sym] = pair[1].to_sym 30: } 31: @mark_to_op_map = @op_to_mark_map.invert 32: end 33: when :CHANMODES 34: @modes = {} 35: value.split(",").each_with_index do |s, kind| 36: s.scan(/./).each {|c| 37: @modes[c.to_sym] = kind 38: } 39: end 40: end 41: end