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

#ignorecase, #value

Instance Method Summary collapse

Methods inherited from Character

#match, #to_regexp

Methods inherited from Atom

#==, #casefold?, #initialize, #inspect

Constructor Details

This class inherits a constructor from Reginald::Atom

Instance Attribute Details

#negateObject

Returns the value of attribute negate.



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

def negate
  @negate
end

Instance Method Details

#bracketed?Boolean

Returns:

  • (Boolean)


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

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

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


58
59
60
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 58

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

#freezeObject

:nodoc:



62
63
64
65
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 62

def freeze #:nodoc:
  negate.freeze
  super
end

#ignorecase=(ignorecase) ⇒ Object



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

def ignorecase=(ignorecase)
  if to_s !~ /\A\[:.*:\]\Z/
    super
  end
end

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 53

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)


33
34
35
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 33

def literal?
  false
end

#negated?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 26

def negated?
  negate ? true : false
end

#to_s(parent = false) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rack/mount/vendor/reginald/reginald/character_class.rb', line 41

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