Parent

Cinch::Pattern

@api private

Attributes

pattern[R]
prefix[R]
suffix[R]

Public Class Methods

new(prefix, pattern, suffix) click to toggle source
# File lib/cinch/pattern.rb, line 27
def initialize(prefix, pattern, suffix)
  @prefix, @pattern, @suffix = prefix, pattern, suffix
end
obj_to_r(obj) click to toggle source

@param [String, Regexp, NilClass, Proc, to_s] obj The object to

convert to a regexp

@return [Regexp, nil]

# File lib/cinch/pattern.rb, line 7
def self.obj_to_r(obj)
  case obj
  when Regexp, NilClass
    return obj
  else
    return Regexp.new(Regexp.escape(obj.to_s))
  end
end
resolve_proc(obj, msg = nil) click to toggle source
# File lib/cinch/pattern.rb, line 16
def self.resolve_proc(obj, msg = nil)
  if obj.is_a?(Proc)
    return resolve_proc(obj.call(msg), msg)
  else
    return obj
  end
end

Public Instance Methods

to_r(msg = nil) click to toggle source
# File lib/cinch/pattern.rb, line 31
def to_r(msg = nil)
  prefix  = Pattern.obj_to_r(Pattern.resolve_proc(@prefix, msg))
  suffix  = Pattern.obj_to_r(Pattern.resolve_proc(@suffix, msg))
  pattern = Pattern.resolve_proc(@pattern, msg)

  case pattern
  when Regexp, NilClass
    /#{prefix}#{pattern}#{suffix}/
  else
    /^#{prefix}#{Pattern.obj_to_r(pattern)}#{suffix}$/
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.