Class: Reginald::CharacterClass

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

Constant Summary collapse

ALNUM =
new(':alnum:').freeze
ALPHA =
new(':alpha:').freeze
ASCII =
new(':ascii:').freeze
BLANK =
new(':blank:').freeze
CNTRL =
new(':cntrl:').freeze
DIGIT =
new(':digit:').freeze
GRAPH =
new(':graph:').freeze
LOWER =
new(':lower:').freeze
new(':print:').freeze
PUNCT =
new(':punct:').freeze
SPACE =
new(':space:').freeze
UPPER =
new(':upper:').freeze
WORD =
new(':word:').freeze
XDIGIT =
new(':xdigit:').freeze

Instance Attribute Summary collapse

Attributes inherited from Character

#quantifier

Attributes inherited from Atom

#value

Instance Method Summary collapse

Methods inherited from Character

#==, #match, #to_regexp

Methods inherited from Atom

#inspect

Instance Attribute Details

#negateObject

Returns the value of attribute negate.



18
19
20
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 18

def negate
  @negate
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(other)
  other.is_a?(self.class) &&
    negate == other.negate &&
    super
end

#freezeObject



47
48
49
50
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 47

def freeze
  negate.freeze
  super
end

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 36

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

#literal?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 24

def literal?
  false
end

#negated?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 20

def negated?
  negate ? true : false
end

#to_sObject



28
29
30
31
32
33
34
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 28

def to_s
  if value == '.' || value =~ /^\\[dDsSwW]$/
    super
  else
    "[#{negate && '^'}#{value}]#{quantifier}"
  end
end