Class: Reginald::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/mount/vendor/reginald/reginald/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/reginald/reginald/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/reginald/reginald/group.rb', line 3

def capture
  @capture
end

#expressionObject (readonly)

Returns the value of attribute expression.



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

def expression
  @expression
end

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#quantifierObject (readonly)

Returns the value of attribute quantifier.



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

def quantifier
  @quantifier
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



65
66
67
68
69
70
71
72
# File 'lib/rack/mount/vendor/reginald/reginald/group.rb', line 65

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

#capture?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/rack/mount/vendor/reginald/reginald/group.rb', line 61

def capture?
  capture
end

#dup(options = {}) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/rack/mount/vendor/reginald/reginald/group.rb', line 41

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)


74
75
76
77
78
79
80
81
# File 'lib/rack/mount/vendor/reginald/reginald/group.rb', line 74

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

#freezeObject

:nodoc:



83
84
85
86
# File 'lib/rack/mount/vendor/reginald/reginald/group.rb', line 83

def freeze #:nodoc:
  expression.freeze if expression
  super
end

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/rack/mount/vendor/reginald/reginald/group.rb', line 57

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

#inspectObject

:nodoc:



49
50
51
# File 'lib/rack/mount/vendor/reginald/reginald/group.rb', line 49

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/reginald/reginald/group.rb', line 23

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

#match(char) ⇒ Object



53
54
55
# File 'lib/rack/mount/vendor/reginald/reginald/group.rb', line 53

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

#option_namesObject



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

def option_names
  %w( quantifier capture index name )
end

#to_regexpObject



37
38
39
# File 'lib/rack/mount/vendor/reginald/reginald/group.rb', line 37

def to_regexp
  Regexp.compile("\\A#{to_s}\\Z")
end

#to_s(parent = false) ⇒ Object



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