Class: Reginald::Expression
- Inherits:
-
Collection
- Object
- Array
- Collection
- Reginald::Expression
- Defined in:
- lib/rack/mount/vendor/reginald/reginald/expression.rb
Instance Attribute Summary collapse
-
#extended ⇒ Object
Returns the value of attribute extended.
-
#ignorecase ⇒ Object
Returns the value of attribute ignorecase.
-
#multiline ⇒ Object
Returns the value of attribute multiline.
Class Method Summary collapse
Instance Method Summary collapse
- #casefold? ⇒ Boolean
-
#eql?(other) ⇒ Boolean
:nodoc:.
-
#initialize(*args) ⇒ Expression
constructor
A new instance of Expression.
-
#inspect ⇒ Object
:nodoc:.
-
#literal? ⇒ Boolean
Returns true if expression could be treated as a literal string.
- #options ⇒ Object
- #options=(flag) ⇒ Object
- #to_s(parent = false) ⇒ Object
Methods inherited from Collection
#==, #freeze, #include?, #match, #to_regexp
Constructor Details
#initialize(*args) ⇒ Expression
Returns a new instance of Expression.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 17 def initialize(*args) @multiline = @ignorecase = @extended = nil if args.length == 1 && args.first.instance_of?(Array) super(args.first) else args = args.map { |e| e.instance_of?(String) ? Character.new(e) : e } super(args) end end |
Instance Attribute Details
#extended ⇒ Object
Returns the value of attribute extended.
4 5 6 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 4 def extended @extended end |
#ignorecase ⇒ Object
Returns the value of attribute ignorecase.
3 4 5 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 3 def ignorecase @ignorecase end |
#multiline ⇒ Object
Returns the value of attribute multiline.
4 5 6 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 4 def multiline @multiline end |
Class Method Details
.reduce(expression_or_atom, atom = nil) ⇒ Object
:nodoc:
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 6 def self.reduce(expression_or_atom, atom = nil) #:nodoc: if expression_or_atom.is_a?(Expression) expression_or_atom << atom if atom new(*expression_or_atom) elsif atom.nil? new(expression_or_atom) else new(expression_or_atom, atom) end end |
Instance Method Details
#casefold? ⇒ Boolean
79 80 81 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 79 def casefold? ignorecase end |
#eql?(other) ⇒ Boolean
:nodoc:
83 84 85 86 87 88 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 83 def eql?(other) #:nodoc: super && !!self.multiline == !!other.multiline && !!self.ignorecase == !!other.ignorecase && !!self.extended == !!other.extended end |
#inspect ⇒ Object
:nodoc:
75 76 77 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 75 def inspect #:nodoc: "#<Expression #{to_s.inspect}>" end |
#literal? ⇒ Boolean
Returns true if expression could be treated as a literal string.
A Expression is literal if all its elements are literal.
40 41 42 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 40 def literal? !ignorecase && all? { |e| e.literal? } end |
#options ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 44 def flag = 0 flag |= Regexp::MULTILINE if multiline flag |= Regexp::IGNORECASE if ignorecase flag |= Regexp::EXTENDED if extended flag end |
#options=(flag) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 52 def (flag) self.multiline = flag & Regexp::MULTILINE != 0 self.ignorecase = flag & Regexp::IGNORECASE != 0 self.extended = flag & Regexp::EXTENDED != 0 nil end |
#to_s(parent = false) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rack/mount/vendor/reginald/reginald/expression.rb', line 59 def to_s(parent = false) if parent || == 0 map { |e| e.to_s(parent) }.join else with, without = [], [] multiline ? (with << 'm') : (without << 'm') ignorecase ? (with << 'i') : (without << 'i') extended ? (with << 'x') : (without << 'x') with = with.join without = without.any? ? "-#{without.join}" : '' "(?#{with}#{without}:#{map { |e| e.to_s(true) }.join})" end end |