Class: Regin::Group
- Inherits:
-
Object
- Object
- Regin::Group
- Defined in:
- lib/rack/mount/vendor/regin/regin/group.rb
Instance Attribute Summary collapse
-
#capture ⇒ Object
readonly
Returns the value of attribute capture.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#lookahead ⇒ Object
readonly
Returns the value of attribute lookahead.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#quantifier ⇒ Object
readonly
Returns the value of attribute quantifier.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
- #capture? ⇒ Boolean
- #dup(options = {}) ⇒ Object
-
#eql?(other) ⇒ Boolean
:nodoc:.
- #include?(char) ⇒ Boolean
-
#initialize(expression, options = {}) ⇒ Group
constructor
A new instance of Group.
-
#inspect ⇒ Object
:nodoc:.
-
#literal? ⇒ Boolean
Returns true if expression could be treated as a literal string.
- #match(char) ⇒ Object
- #option_names ⇒ Object
- #to_regexp(anchored = false) ⇒ Object
- #to_s(parent = false) ⇒ Object
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, = {}) @quantifier = @index = @name = nil @capture = true @expression = expression.dup() @quantifier = [:quantifier] if .key?(:quantifier) @lookahead = [:lookahead] if .key?(:lookahead) @capture = [:capture] if .key?(:capture) @index = [:index] if .key?(:index) @name = [:name] if .key?(:name) end |
Instance Attribute Details
#capture ⇒ Object (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 |
#expression ⇒ Object (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 |
#index ⇒ Object (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 |
#lookahead ⇒ Object (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 |
#name ⇒ Object (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 |
#quantifier ⇒ Object (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
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( = {}) = option_names.inject({}) do |h, m| h[m.to_sym] = send(m) h end self.class.new(expression, .merge()) end |
#eql?(other) ⇒ Boolean
:nodoc:
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
64 65 66 |
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 64 def include?(char) expression.include?(char) end |
#inspect ⇒ Object
: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.
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_names ⇒ Object
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. "(#{capture ? '' : '?:'}#{expression.to_s(parent)})#{quantifier}" elsif capture == false "#{expression.to_s}#{quantifier}" else "(#{expression.to_s})#{quantifier}" end end |