}\r
end\r
\r
+ # We introduce the 'downcase' method, which maps downcase() to all the Array\r
+ # elements, properly failing when the elements don't have a downcase method\r
+ #\r
+ def downcase\r
+ self.map { |el| el.downcase }\r
+ end\r
+\r
# Modifying methods which we don't handle yet are made private\r
#\r
private :[]=, :collect!, :map!, :fill, :flatten!\r
if self.class == Netmask\r
return self if fits_with_server_and_casemap?(opts)\r
end\r
- return self.fullform.to_irc_netmask(server_and_casemap.merge(opts))\r
+ return self.downcase.to_irc_netmask(opts)\r
end\r
\r
# Converts the receiver into a User with the given (optional)\r
end\r
\r
# We enhance the [] method by allowing it to pick an element that matches\r
- # a given Netmask or String\r
+ # a given Netmask, a String or a Regexp\r
+ # TODO take into consideration the opportunity to use select() instead of\r
+ # find(), and/or a way to let the user choose which one to take (second\r
+ # argument?)\r
#\r
def [](*args)\r
if args.length == 1\r
self.find { |mask|\r
mask.matches?(args[0].to_irc_netmask(:casemap => mask.casemap))\r
}\r
+ when Regexp\r
+ self.find { |mask|\r
+ mask.fullform =~ args[0]\r
+ }\r
else\r
super(*args)\r
end\r
end\r
end\r
\r
+ # Users can be either simply downcased (their nick only)\r
+ # or fully downcased: this will return the fullform downcased\r
+ # according to the given casemap.\r
+ #\r
+ def full_irc_downcase(cmap=casemap)\r
+ self.fullform.irc_downcase(cmap)\r
+ end\r
+\r
+ # full_downcase() will return the fullform downcased according to the\r
+ # User's own casemap\r
+ #\r
+ def full_downcase\r
+ self.full_irc_downcase\r
+ end\r
+\r
# Since to_irc_user runs the same checks on server and channel as\r
# to_irc_netmask, we just try that and return self if it works.\r
#\r
#\r
def to_irc_user(opts={})\r
return self if fits_with_server_and_casemap?(opts)\r
- return self.fullform.to_irc_user(server_and_casemap(opts))\r
+ return self.full_downcase.to_irc_user(opts)\r
end\r
\r
# We can replace everything at once with data from another User\r
@element_class = User\r
end\r
\r
+ # Convenience method: convert the UserList to a list of nicks. The indices\r
+ # are preserved\r
+ #\r
+ def nicks\r
+ self.map { |user| user.nick }\r
+ end\r
+\r
end\r
\r
end\r
super(Channel, ar)\r
end\r
\r
+ # Convenience method: convert the ChannelList to a list of channel names.\r
+ # The indices are preserved\r
+ #\r
+ def names\r
+ self.map { |chan| chan.name }\r
+ end\r
+\r
end\r
\r
end\r