lib/ircsupport/masks.rb in ircsupport-0.1.0 vs lib/ircsupport/masks.rb in ircsupport-0.2.0

- old
+ new

@@ -5,10 +5,13 @@ # @private @@mask_wildcard = '[\x01-\xFF]{0,}' # @private @@mask_optional = '[\x01-\xFF]{1,1}' + module_function + + # Match strings to an IRC mask. # @param [String] mask The mask to match against. # @param [String] string The string to match against the mask. # @param [Symbol] casemapping The IRC casemapping to use in the match. # @return [Boolean] Will be true of the string matches the mask. def matches_mask(mask, string, casemapping = :rfc1459) @@ -22,10 +25,11 @@ mask = Regexp.new(mask, nil, 'n') return true if string =~ /\A#{mask}\z/ return false end + # Match strings to multiple IRC masks. # @param [Array] mask The masks to match against. # @param [Array] strings The strings to match against the masks. # @param [Symbol] casemapping The IRC casemapping to use in the match. # @return [Hash] Each mask that was matched will be present as a key, # and the values will be arrays of the strings that matched. @@ -40,10 +44,11 @@ end end return results end + # Normalize (expand) an IRC mask. # @param [String] mask A partial mask (e.g. 'foo*'). # @return [String] A normalized mask (e.g. 'foo*!*@*). def normalize_mask(mask) mask = mask.dup mask.gsub!(/\*{2,}/, '*') @@ -64,9 +69,7 @@ parts[2].gsub!(/@/, '') if parts[2] (1..2).each { |i| parts[i] ||= '*' } return parts[0] + "!" + parts[1] + "@" + parts[2] end - - module_function :matches_mask, :matches_mask_array, :normalize_mask end end