Parent

Regin::Expression

Attributes

extended[R]
ignorecase[R]
multiline[R]

Public Class Methods

new(*args) click to toggle source
# File lib/regin/expression.rb, line 5
def initialize(*args)
  args, options = extract_options(args)

  @multiline = @ignorecase = @extended = nil

  if args.length == 1 && args.first.instance_of?(Array)
    super(args.first)
  else
    args = args.map { |e| e.instance_of?(String) ? Character.new(e) : e }
    super(args)
  end

  self.multiline  = options[:multiline] if options.key?(:multiline)
  self.ignorecase = options[:ignorecase] if options.key?(:ignorecase)
  self.extended   = options[:extended] if options.key?(:extended)
end

Public Instance Methods

+(other) click to toggle source
# File lib/regin/expression.rb, line 61
def +(other)
  ary = other.is_a?(self.class) ? other.internal_array : other
  ary = @array + ary + [options.to_h(true)]
  self.class.new(*ary)
end
anchored?() click to toggle source
# File lib/regin/expression.rb, line 29
def anchored?
  anchored_to_start? && anchored_to_end?
end
anchored_to_end?() click to toggle source
# File lib/regin/expression.rb, line 37
def anchored_to_end?
  last.is_a?(Anchor) && last == '\Z'
end
anchored_to_end_of_line?() click to toggle source
# File lib/regin/expression.rb, line 49
def anchored_to_end_of_line?
  anchored_to_end? || (last.is_a?(Anchor) && last == '$')
end
anchored_to_line?() click to toggle source
# File lib/regin/expression.rb, line 41
def anchored_to_line?
  anchored_to_start_of_line? && anchored_to_end_of_line?
end
anchored_to_start?() click to toggle source
# File lib/regin/expression.rb, line 33
def anchored_to_start?
  first.is_a?(Anchor) && first == '\A'
end
anchored_to_start_of_line?() click to toggle source
# File lib/regin/expression.rb, line 45
def anchored_to_start_of_line?
  anchored_to_start? || (first.is_a?(Anchor) && first == '^')
end
casefold?() click to toggle source
# File lib/regin/expression.rb, line 95
def casefold?
  ignorecase
end
dup(options = {}) click to toggle source
# File lib/regin/expression.rb, line 67
def dup(options = {})
  expression = super()
  expression.multiline  = options[:multiline] if options.key?(:multiline)
  expression.ignorecase = options[:ignorecase] if options.key?(:ignorecase)
  expression.extended   = options[:extended] if options.key?(:extended)
  expression
end
flags() click to toggle source
# File lib/regin/expression.rb, line 57
def flags
  options.to_i
end
literal?() click to toggle source

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

A Expression is literal if all its elements are literal.

# File lib/regin/expression.rb, line 25
def literal?
  !ignorecase && all? { |e| e.literal? }
end
options?() click to toggle source
# File lib/regin/expression.rb, line 53
def options?
  options.any?(true)
end
to_s(parent = false) click to toggle source
# File lib/regin/expression.rb, line 75
def to_s(parent = false)
  if parent || !options?
    map { |e| e.to_s(parent) }.join
  else
    with, without = [], []
    multiline ? (with << 'm') : (without << 'm')
    ignorecase ? (with << 'i') : (without << 'i')
    extended ? (with << 'x') : (without << 'x')

    with = with.join
    without = without.any? ? "-#{without.join}" : ''

    "(?#{with}#{without}:#{map { |e| e.to_s(true) }.join})"
  end
end

Protected Instance Methods

extended=(extended) click to toggle source
# File lib/regin/expression.rb, line 122
def extended=(extended)
  @extended = extended
end
ignorecase=(ignorecase) click to toggle source
# File lib/regin/expression.rb, line 115
def ignorecase=(ignorecase)
  if @ignorecase.nil?
    @array.map! { |e| e.dup(:ignorecase => ignorecase) }
    @ignorecase = ignorecase
  end
end
multiline=(multiline) click to toggle source
# File lib/regin/expression.rb, line 111
def multiline=(multiline)
  @multiline = multiline
end
options() click to toggle source
# File lib/regin/expression.rb, line 107
def options
  Options.new(multiline, ignorecase, extended)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.