Class: IRC::ISupport

Inherits:
Object
  • Object
show all
Defined in:
lib/irc/isupport.rb

Instance Method Summary collapse

Constructor Details

#initialize(*messages) ⇒ ISupport

messages - IRC::Messages.


4
5
6
7
8
9
10
11
# File 'lib/irc/isupport.rb', line 4

def initialize(*messages)
  unless valid_messages? messages
    raise ArgumentError
  end

  pairs   = messages.map(&:params).flatten
  @parsed = Hash[pairs.map { |param| param.split("=") }]
end

Instance Method Details

#casemappingObject


13
14
15
# File 'lib/irc/isupport.rb', line 13

def casemapping
  @parsed.fetch("CASEMAPPING", :rfc1459).to_sym
end

#channel_id_lengthsObject


55
56
57
58
59
60
61
62
63
# File 'lib/irc/isupport.rb', line 55

def channel_id_lengths
  pairs = @parsed.fetch("IDCHAN", "").split(",")

  pairs.each_with_object Hash.new do |pair, result|
    prefix, length = pair.split ":"

    result[prefix] = length.to_i
  end
end

#channel_lengthObject


39
40
41
# File 'lib/irc/isupport.rb', line 39

def channel_length
  @parsed.fetch("CHANNELLEN", 200).to_i
end

#channel_limitsObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/irc/isupport.rb', line 17

def channel_limits
  pairs = @parsed.fetch("CHANLIMIT", "").split ","

  pairs.each_with_object Hash.new do |pair, result|
    prefixes, limit = pair.split ":"

    prefixes.each_char do |prefix|
      if limit
        result[prefix] = limit.to_i 
      else
        result[prefix] = Float::INFINITY
      end
    end
  end
end

#channel_modesObject


33
34
35
36
37
# File 'lib/irc/isupport.rb', line 33

def channel_modes
  parts = @parsed["CHANMODES"].split(",").map(&:chars)

  Hash[[:A, :B, :C, :D].zip parts]
end

#channel_typesObject


43
44
45
# File 'lib/irc/isupport.rb', line 43

def channel_types
  @parsed.fetch("CHANTYPES", "#&").chars
end

#exception_modeObject


51
52
53
# File 'lib/irc/isupport.rb', line 51

def exception_mode
  @parsed["EXCEPT"]
end

#exceptions?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/irc/isupport.rb', line 47

def exceptions?
  @parsed.key? "EXCEPT"
end

#invite_exception_modeObject


69
70
71
# File 'lib/irc/isupport.rb', line 69

def invite_exception_mode
  @parsed["INVEX"]
end

#invite_exceptions?Boolean

Returns:

  • (Boolean)

65
66
67
# File 'lib/irc/isupport.rb', line 65

def invite_exceptions?
  @parsed.key? "INVEX"
end

#kick_lengthObject


73
74
75
# File 'lib/irc/isupport.rb', line 73

def kick_length
  @parsed["KICKLEN"].to_i
end

#list?Boolean

Returns:

  • (Boolean)

105
106
107
# File 'lib/irc/isupport.rb', line 105

def list?
  @parsed.key? "SAFELIST"
end

#max_list_itemsObject


77
78
79
80
81
82
83
84
85
# File 'lib/irc/isupport.rb', line 77

def max_list_items
  pairs = @parsed["MAXLIST"].split(",")

  pairs.each_with_object Hash.new do |pair, result|
    modes, max = pair.split(":")

    modes.each_char { |char| result[char.to_sym] = max.to_i }
  end
end

#max_modesObject


87
88
89
# File 'lib/irc/isupport.rb', line 87

def max_modes
  @parsed.fetch("MODES", 3).to_i
end

#maximum_targetsObject


121
122
123
124
125
126
127
128
129
# File 'lib/irc/isupport.rb', line 121

def maximum_targets
  pairs = @parsed.fetch("TARGMAX", "").split(",")

  pairs.each_with_object Hash.new do |pair, result|
    command, max = pair.split(":")

    result[command.downcase.to_sym] = max.to_i
  end
end

#networkObject


91
92
93
# File 'lib/irc/isupport.rb', line 91

def network
  @parsed["NETWORK"]
end

#nick_lengthObject


95
96
97
# File 'lib/irc/isupport.rb', line 95

def nick_length
  @parsed.fetch("NICKLEN", 9).to_i
end

#prefixObject


99
100
101
102
103
# File 'lib/irc/isupport.rb', line 99

def prefix
  modes, prefixes = @parsed.fetch("PREFIX", "(ov)@+")[1..-1].split ")"

  Hash[modes.chars.zip prefixes.chars]
end

#standardsObject


117
118
119
# File 'lib/irc/isupport.rb', line 117

def standards
  @parsed.fetch("STD", "").split(",")
end

#status_messagesObject


113
114
115
# File 'lib/irc/isupport.rb', line 113

def status_messages
  @parsed.fetch("STATUSMSG", "").chars
end

#status_messages?Boolean

Returns:

  • (Boolean)

109
110
111
# File 'lib/irc/isupport.rb', line 109

def status_messages?
  @parsed.key? "STATUSMSG"
end

#topic_lengthObject


131
132
133
134
135
# File 'lib/irc/isupport.rb', line 131

def topic_length
  @parsed.fetch("TOPICLEN").to_i
rescue KeyError
  return Float::INFINITY
end