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
15
# 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)
  @lookahead  = options[:lookahead] if options.key?(:lookahead)
  @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

#lookaheadObject (readonly)

Returns the value of attribute lookahead.



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

def lookahead
  @lookahead
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:



72
73
74
75
76
77
78
79
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 72

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

#capture?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 68

def capture?
  capture
end

#dup(options = {}) ⇒ Object



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

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)


81
82
83
84
85
86
87
88
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 81

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)


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

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

#inspectObject

:nodoc:



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

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)


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

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

#match(char) ⇒ Object



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

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

#option_namesObject



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

def option_names
  %w( quantifier capture index name )
end

#to_regexp(anchored = false) ⇒ Object



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

def to_regexp(anchored = false)
  re = to_s
  re = "\\A#{re}\\Z" if anchored
  Regexp.compile(re)
end

#to_s(parent = false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 28

def to_s(parent = false)
  if lookahead == :postive
    "(?=#{expression.to_s(parent)})#{quantifier}"
  elsif lookahead == :negative
    "(?!#{expression.to_s(parent)})#{quantifier}"
  elsif !expression.options?
    "(#{capture ? '' : '?:'}#{expression.to_s(parent)})#{quantifier}"
  elsif capture == false
    "#{expression.to_s}#{quantifier}"
  else
    "(#{expression.to_s})#{quantifier}"
  end
end