class Net::IRC::Message::ModeParser

Constants

NO_PARAM
ONE_PARAM
ONE_PARAM_FOR_POSITIVE
ONE_PARAM_MASK

Public Class Methods

new() click to toggle source
   # File lib/net/irc/message/modeparser.rb
 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

Public Instance Methods

mark_to_op(mark) click to toggle source
   # File lib/net/irc/message/modeparser.rb
18 def mark_to_op(mark)
19         mark.empty? ? nil : @mark_to_op_map[mark.to_sym]
20 end
parse(arg) click to toggle source
   # File lib/net/irc/message/modeparser.rb
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
set(key, value) click to toggle source
   # File lib/net/irc/message/modeparser.rb
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