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