Class: Reginald::Character

Inherits:
Atom
  • Object
show all
Defined in:
lib/rack/mount/vendor/reginald/reginald/character.rb

Direct Known Subclasses

CharacterClass

Instance Attribute Summary collapse

Attributes inherited from Atom

#ignorecase, #value

Instance Method Summary collapse

Methods inherited from Atom

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

Constructor Details

This class inherits a constructor from Reginald::Atom

Instance Attribute Details

#quantifierObject

Returns the value of attribute quantifier.



3
4
5
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 3

def quantifier
  @quantifier
end

Instance Method Details

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


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

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

#freezeObject

:nodoc:



40
41
42
43
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 40

def freeze #:nodoc:
  quantifier.freeze
  super
end

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


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

def include?(char)
  if ignorecase
    value.downcase == char.downcase
  else
    value == char
  end
end

#literal?Boolean

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

A Character is literal is there is no quantifier attached to it.

Returns:

  • (Boolean)


8
9
10
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 8

def literal?
  quantifier.nil? && !ignorecase
end

#match(char) ⇒ Object



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

def match(char)
  to_regexp.match(char)
end

#to_regexpObject



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

def to_regexp
  Regexp.compile("\\A#{to_s(true)}\\Z", ignorecase)
end

#to_s(parent = false) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 12

def to_s(parent = false)
  if !parent && ignorecase
    "(?i-mx:#{value})#{quantifier}"
  else
    "#{value}#{quantifier}"
  end
end