Class: Regin::CharacterClass

Inherits:
Character show all
Defined in:
lib/rack/mount/vendor/regin/regin/character_class.rb

Instance Attribute Summary collapse

Attributes inherited from Character

#quantifier

Attributes inherited from Atom

#ignorecase, #value

Instance Method Summary collapse

Methods inherited from Character

#match, #to_regexp

Methods inherited from Atom

#==, #casefold?, #dup, #inspect

Constructor Details

#initialize(value, options = {}) ⇒ CharacterClass

Returns a new instance of CharacterClass.



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

def initialize(value, options = {})
  @negate = options[:negate]
  super
end

Instance Attribute Details

#negateObject (readonly)

Returns the value of attribute negate.



12
13
14
# File 'lib/rack/mount/vendor/regin/regin/character_class.rb', line 12

def negate
  @negate
end

Instance Method Details

#bracketed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rack/mount/vendor/regin/regin/character_class.rb', line 25

def bracketed?
  value != '.' && value !~ /^\\[dDsSwW]$/
end

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


46
47
48
# File 'lib/rack/mount/vendor/regin/regin/character_class.rb', line 46

def eql?(other) #:nodoc:
  super && negate == other.negate
end

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/rack/mount/vendor/regin/regin/character_class.rb', line 41

def include?(char)
  re = quantifier ? to_s.sub(/#{Regexp.escape(quantifier)}$/, '') : to_s
  Regexp.compile("\\A#{re}\\Z").match(char)
end

#literal?Boolean

Returns true if expression could be treated as a literal string.

A CharacterClass is never literal.

Returns:

  • (Boolean)


21
22
23
# File 'lib/rack/mount/vendor/regin/regin/character_class.rb', line 21

def literal?
  false
end

#negated?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rack/mount/vendor/regin/regin/character_class.rb', line 14

def negated?
  negate ? true : false
end

#option_namesObject



8
9
10
# File 'lib/rack/mount/vendor/regin/regin/character_class.rb', line 8

def option_names
  %w( negate ) + super
end

#to_s(parent = false) ⇒ Object



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

def to_s(parent = false)
  if bracketed?
    if !parent && ignorecase
      "(?i-mx:[#{negate && '^'}#{value}])#{quantifier}"
    else
      "[#{negate && '^'}#{value}]#{quantifier}"
    end
  else
    super
  end
end