Class: Regin::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/mount/vendor/regin/regin/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression, options = {}) ⇒ Group

Returns a new instance of Group.



5
6
7
8
9
10
11
12
13
14
# File 'lib/rack/mount/vendor/regin/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

Instance Attribute Details

#captureObject (readonly)

Returns the value of attribute capture.



3
4
5
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 3

def capture
  @capture
end

#expressionObject (readonly)

Returns the value of attribute expression.



3
4
5
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 3

def expression
  @expression
end

#indexObject (readonly)

Returns the value of attribute index.



3
4
5
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 3

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 3

def name
  @name
end

#quantifierObject (readonly)

Returns the value of attribute quantifier.



3
4
5
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 3

def quantifier
  @quantifier
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



67
68
69
70
71
72
73
74
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 67

def ==(other) #:nodoc:
  case other
  when String
    other == to_s
  else
    eql?(other)
  end
end

#capture?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 63

def capture?
  capture
end

#dup(options = {}) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rack/mount/vendor/regin/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

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


76
77
78
79
80
81
82
83
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 76

def eql?(other) #:nodoc:
  other.is_a?(self.class) &&
    self.expression == other.expression &&
    self.quantifier == other.quantifier &&
    self.capture == other.capture &&
    self.index == other.index &&
    self.name == other.name
end

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 59

def include?(char)
  expression.include?(char)
end

#inspectObject

:nodoc:



51
52
53
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 51

def inspect #:nodoc:
  to_s.inspect
end

#literal?Boolean

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.

Returns:

  • (Boolean)


23
24
25
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 23

def literal?
  quantifier.nil? && expression.literal?
end

#match(char) ⇒ Object



55
56
57
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 55

def match(char)
  to_regexp.match(char)
end

#option_namesObject



16
17
18
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 16

def option_names
  %w( quantifier capture index name )
end

#to_regexp(anchored = false) ⇒ Object



37
38
39
40
41
# File 'lib/rack/mount/vendor/regin/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) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/rack/mount/vendor/regin/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