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.
-
#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 |
# 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) @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 |
#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:
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
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( = {}) = option_names.inject({}) do |h, m| h[m.to_sym] = send(m) h end self.class.new(expression, .merge()) end |
#eql?(other) ⇒ Boolean
:nodoc:
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
59 60 61 |
# File 'lib/rack/mount/vendor/regin/regin/group.rb', line 59 def include?(char) expression.include?(char) end |
#inspect ⇒ Object
: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.
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_names ⇒ Object
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. "(#{capture ? '' : '?:'}#{expression.to_s(parent)})#{quantifier}" elsif capture == false "#{expression.to_s}#{quantifier}" else "(#{expression.to_s})#{quantifier}" end end |