lib/marvin/util.rb in Sutto-marvin-0.4.0 vs lib/marvin/util.rb in Sutto-marvin-0.8.0.0
- old
+ new
@@ -10,11 +10,12 @@
# Return the channel-name version of a string by
# appending "#" to the front if it doesn't already
# start with it.
def channel_name(name)
- return name.to_s[0..0] == "#" ? name.to_s : "##{name}"
+ name = name.to_s
+ name =~ /^\#/ ? name : "##{name}"
end
alias chan channel_name
def arguments(input)
prefix, ending = input.split(":", 2)
@@ -24,11 +25,17 @@
end
# Specifies the last parameter of a response, used to
# specify parameters which have spaces etc (for example,
# the actual message part of a response).
- def last_param(section)
- section && ":#{section.to_s.strip}"
+ def last_param(section, ignore_prefix = true)
+ content = section.to_s.strip
+ return if content.blank?
+ if content =~ /\s+/ && (ignore_prefix || content !~ /^:/)
+ ":#{content}"
+ else
+ content
+ end
end
alias lp last_param
# Converts a glob-like pattern into a regular
# expression for easy / fast matching. Code is
\ No newline at end of file