Class RegexPath
In: lib/regex_path.rb
Parent: Object
Copyright:Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
Author:Nicolas Pouillard <ertai@lrde.epita.fr>.
License:Gnu General Public License.
Revision:$Id: /w/fey/ruby_ex/trunk/lib/regex_path.rb 22076 2006-02-21T14:40:09.796627Z pouillar $

Methods

captured?   empty?   final?   initialize_copy   negative?   new   root?   split  

Classes and Modules

Class RegexPath::Segment

Attributes

segments  [R] 

Public Class methods

[Source]

# File lib/regex_path.rb, line 51
  def initialize ( orig )
    raise ArgumentError, 'Argument must be a string' unless orig.is_a?(String)
    @segments = []
    orig =~ /^(\\N)?(\/)?(.*?)(\\Z)?$/
    str = '/' + $3
    @negative = !!$1
    @root = !!$2
    @final = !!$4
    cap = /(\(\))/
    neg = /(!)/
    neg_cap = /(?:#{cap}?#{neg}?|#{neg}?#{cap}?)/
    while str =~ /^\/#{neg_cap}((?:\\.|[^\\\/])+)?/
      m = Regexp.last_match
      str = m.post_match
      key = m[5]
      @segments << Segment.new((key.nil?)? '' : key,
                               m[1] || m[3], m[2] || m[4])
    end
    unless str.nil? or str.empty? or str == '\\'
      raise ArgumentError, "Parsing error trailing chars '#{str}' in '#{orig}'"
    end
  end

Public Instance methods

[Source]

# File lib/regex_path.rb, line 80
  def captured?
    ! @segments.empty? and @segments.first.captured?
  end

[Source]

# File lib/regex_path.rb, line 96
  def empty?
    @segments.empty?
  end

[Source]

# File lib/regex_path.rb, line 92
  def final?
    @final
  end

[Source]

# File lib/regex_path.rb, line 74
  def initialize_copy ( rhs )
    @segments = rhs.segments.dup
    @root = rhs.root?
    @negative = rhs.negative?
  end

[Source]

# File lib/regex_path.rb, line 84
  def negative?
    @negative
  end

[Source]

# File lib/regex_path.rb, line 88
  def root?
    @root
  end

[Source]

# File lib/regex_path.rb, line 100
  def split
    copy = dup
    [copy.segments.shift, copy]
  end

[Validate]