Sha256: c4716d00696a4376be027ecf3fcefde0fc5f60b57fff9f4fb7de240a310c89d8

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

module Marvin
  module Util
      
      GLOB_PATTERN_MAP = {
        '*' => '.*',
        '?' => '.',
        '[' => '[',
        ']' => ']'
      }
      
      # 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)
        name = name.to_s
        name =~ /^\#/ ? name : "##{name}"
      end
      alias chan channel_name
      
      def arguments(input)
        prefix, ending = input.split(":", 2)
        prefix = prefix.split(" ")
        prefix << ending unless ending.blank?
        return prefix
      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, 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
      # from PLEAC at http://pleac.sourceforge.net/pleac_ruby/patternmatching.html
      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
     
      extend self
     
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
Sutto-marvin-0.8.0.0 lib/marvin/util.rb
Sutto-marvin-0.8.0.1 lib/marvin/util.rb
marvin-0.8.2 lib/marvin/util.rb
marvin-0.8.1 lib/marvin/util.rb
marvin-0.8.0.2 lib/marvin/util.rb
marvin-0.8.0.1 lib/marvin/util.rb
marvin-0.8.0.0 lib/marvin/util.rb