Module: Marvin::Util
Constant Summary collapse
- GLOB_PATTERN_MAP =
{ '*' => '.*', '?' => '.', '[' => '[', ']' => ']' }
Instance Method Summary collapse
- #arguments(input) ⇒ Object
-
#channel_name(name) ⇒ Object
(also: #chan)
Return the channel-name version of a string by appending “#” to the front if it doesn’t already start with it.
-
#glob2pattern(glob_string) ⇒ Object
Converts a glob-like pattern into a regular expression for easy / fast matching.
-
#last_param(section) ⇒ Object
(also: #lp)
Specifies the last parameter of a response, used to specify parameters which have spaces etc (for example, the actual message part of a response).
Instance Method Details
#arguments(input) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/marvin/util.rb', line 19 def arguments(input) prefix, ending = input.split(":", 2) prefix = prefix.split(" ") prefix << ending unless ending.blank? return prefix end |
#channel_name(name) ⇒ Object Also known as: chan
Return the channel-name version of a string by appending “#” to the front if it doesn’t already start with it.
14 15 16 |
# File 'lib/marvin/util.rb', line 14 def channel_name(name) return name.to_s[0..0] == "#" ? name.to_s : "##{name}" end |
#glob2pattern(glob_string) ⇒ Object
Converts a glob-like pattern into a regular expression for easy / fast matching. Code is from PLEAC at pleac.sourceforge.net/pleac_ruby/patternmatching.html
37 38 39 40 41 42 |
# File 'lib/marvin/util.rb', line 37 def glob2pattern(glob_string) inner_pattern = glob_string.gsub(/(.)/) do |c| GLOB_PATTERN_MAP[c] || Regexp::escape(c) end return Regexp.new("^#{inner_pattern}$") end |
#last_param(section) ⇒ Object Also known as: lp
Specifies the last parameter of a response, used to specify parameters which have spaces etc (for example, the actual message part of a response).
29 30 31 |
# File 'lib/marvin/util.rb', line 29 def last_param(section) section && ":#{section.to_s.strip}" end |