Parent

Regin::Group

Attributes

capture[R]
expression[R]
index[R]
name[R]
quantifier[R]

Public Class Methods

new(expression, options = {}) click to toggle source
# File lib/regin/group.rb, line 5
def initialize(expression, options = {})
  @quantifier = @index = @name = nil
  @capture = true
  @expression = expression.dup(options)

  @quantifier = options[:quantifier] if options.key?(:quantifier)
  @capture    = options[:capture] if options.key?(:capture)
  @index      = options[:index] if options.key?(:index)
  @name       = options[:name] if options.key?(:name)
end

Public Instance Methods

capture?() click to toggle source
# File lib/regin/group.rb, line 63
def capture?
  capture
end
dup(options = {}) click to toggle source
# File lib/regin/group.rb, line 43
def dup(options = {})
  original_options = option_names.inject({}) do |h, m|
    h[m.to_sym] = send(m)
    h
  end
  self.class.new(expression, original_options.merge(options))
end
include?(char) click to toggle source
# File lib/regin/group.rb, line 59
def include?(char)
  expression.include?(char)
end
literal?() click to toggle source

Returns true if expression could be treated as a literal string.

A Group is literal if its expression is literal and it has no quantifier.

# File lib/regin/group.rb, line 23
def literal?
  quantifier.nil? && expression.literal?
end
match(char) click to toggle source
# File lib/regin/group.rb, line 55
def match(char)
  to_regexp.match(char)
end
option_names() click to toggle source
# File lib/regin/group.rb, line 16
def option_names
  %( quantifier capture index name )
end
to_regexp(anchored = false) click to toggle source
# File lib/regin/group.rb, line 37
def to_regexp(anchored = false)
  re = to_s
  re = "\\A#{re}\\Z" if anchored
  Regexp.compile(re)
end
to_s(parent = false) click to toggle source
# File lib/regin/group.rb, line 27
def to_s(parent = false)
  if !expression.options?
    "(#{capture ? '' : '?:'}#{expression.to_s(parent)})#{quantifier}"
  elsif capture == false
    "#{expression.to_s}#{quantifier}"
  else
    "(#{expression.to_s})#{quantifier}"
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.