Module: Rlyeh::NumericReply

Defined in:
lib/rlyeh/numeric_reply.rb

Class Method Summary collapse

Class Method Details

.mapObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rlyeh/numeric_reply.rb', line 4

def map
  @map ||= {
    # Numerics in the range from 001 to 099 are used for client-server
    # connections only and should never travel between servers.
    # Replies generated in the response to commands are found in the range from 200 to 399.
    :welcome => 1,
    :yourhost => 2,
    :created => 3,
    :myinfo => 4,
    :bounce => 5,
    :userhost => 302,
    :ison => 303,
    :away => 301,
    :unaway => 305,
    :nowaway => 306,
    :whoisuser => 311,
    :whoisserver => 312,
    :whoisoperator => 313,
    :whoisidle => 317,
    :endofwhois => 318,
    :whoischannels => 319,
    :whowasuser => 314,
    :endofwhowas => 369,
    :liststart => 321,
    :list => 322,
    :listend => 323,
    :uniqopis => 325,
    :channelmodeis => 324,
    :notopic => 331,
    :topic => 332,
    :inviting => 341,
    :summoning => 342,
    :invitelist => 346,
    :endofinvitelist => 347,
    :exceptlist => 348,
    :endofexceptlist => 349,
    :version => 351,
    :whoreply => 352,
    :endofwho => 315,
    :namreply => 353,
    :endofnames => 366,
    :links => 364,
    :endoflinks => 365,
    :banlist => 367,
    :endofbanlist => 368,
    :info => 371,
    :endofinfo => 374,
    :motdstart => 375,
    :motd => 372,
    :endofmotd => 376,
    :youreoper => 381,
    :rehashing => 382,
    :youreservice => 383,
    :time => 391,
    :usersstart => 392,
    :users => 393,
    :endofusers => 394,
    :nousers => 395,
    :tracelink => 200,
    :traceconnecting => 201,
    :tracehandshake => 202,
    :traceunknown => 203,
    :traceoperator => 204,
    :traceuser => 205,
    :traceserver => 206,
    :traceservice => 207,
    :tracenewtype => 208,
    :traceclass => 209,
    :tracereconnect => 210,
    :tracelog => 261,
    :traceend => 262,
    :statslinkinfo => 211,
    :statscommands => 212,
    :endofstats => 219,
    :statsuptime => 242,
    :statsoline => 243,
    :umodeis => 221,
    :servlist => 234,
    :servlistend => 235,
    :luserclient => 251,
    :luserop => 252,
    :luserunknown => 253,
    :luserchannels => 254,
    :luserme => 255,
    :adminme => 256,
    :adminloc1 => 257,
    :adminloc2 => 258,
    :adminemail => 259,
    :tryagain => 263,

    # Error replies are found in the range from 400 to 599.
    :nosuchnick => 401,
    :nosuchserver => 402,
    :nosuchchannel => 403,
    :cannotsendtochan => 404,
    :toomanychannels => 405,
    :wasnosuchnick => 406,
    :toomanytargets => 407,
    :nosuchservice => 408,
    :noorigin => 409,
    :norecipient => 411,
    :notexttosend => 412,
    :notoplevel => 413,
    :wildtoplevel => 414,
    :badmask => 415,
    :unknowncommand => 421,
    :nomotd => 422,
    :noadmininfo => 423,
    :fileerror => 424,
    :nonicknamegiven => 431,
    :erroneusnickname => 432,
    :nicknameinuse => 433,
    :nickcollision => 436,
    :unavailresource => 437,
    :usernotinchannel => 441,
    :notonchannel => 442,
    :useronchannel => 443,
    :nologin => 444,
    :summondisabled => 445,
    :usersdisabled => 446,
    :notregistered => 451,
    :needmoreparams => 461,
    :alreadyregistred => 462,
    :nopermforhost => 463,
    :passwdmismatch => 464,
    :yourebannedcreep => 465,
    :youwillbebanned => 466,
    :keyset => 467,
    :channelisfull => 471,
    :unknownmode => 472,
    :inviteonlychan => 473,
    :bannedfromchan => 474,
    :badchannelkey => 475,
    :badchanmask => 476,
    :nochanmodes => 477,
    :banlistfull => 478,
    :noprivileges => 481,
    :chanoprivsneeded => 482,
    :cantkillserver => 483,
    :restricted => 484,
    :uniqopprivsneeded => 485,
    :nooperhost => 491,
    :umodeunknownflag => 501,
    :usersdontmatch => 502,
  }
end

.map_invertObject



151
152
153
# File 'lib/rlyeh/numeric_reply.rb', line 151

def map_invert
  @map_invert ||= map.invert
end

.name_to_key(name) ⇒ Object



201
202
203
# File 'lib/rlyeh/numeric_reply.rb', line 201

def name_to_key(name)
  name.intern
end

.name_to_value(name) ⇒ Object



197
198
199
# File 'lib/rlyeh/numeric_reply.rb', line 197

def name_to_value(name)
  numeric_to_value map[name.intern]
end

.numeric_to_key(numeric) ⇒ Object



193
194
195
# File 'lib/rlyeh/numeric_reply.rb', line 193

def numeric_to_key(numeric)
  map_invert[numeric]
end

.numeric_to_value(numeric) ⇒ Object



189
190
191
# File 'lib/rlyeh/numeric_reply.rb', line 189

def numeric_to_value(numeric)
  numeric.to_s.rjust(3, '0')
end

.to_key(value) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/rlyeh/numeric_reply.rb', line 172

def to_key(value)
  case value
  when Integer
    numeric_to_key value
  when Symbol
    name_to_key value
  else
    str = value.to_s
    begin
      numeric = Integer(str)
      numeric_to_key numeric
    rescue ArgumentError
      name_to_key str
    end
  end
end

.to_value(value) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rlyeh/numeric_reply.rb', line 155

def to_value(value)
  case value
  when Integer
    numeric_to_value value
  when Symbol
    name_to_value value
  else
    str = value.to_s
    begin
      numeric = Integer(str)
      numeric_to_value numeric
    rescue ArgumentError
      name_to_value str
    end
  end
end