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?, #dup, #inspect

Constructor Details

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

Returns a new instance of Character.



5
6
7
8
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 5

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

Instance Attribute Details

#quantifierObject (readonly)

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)


45
46
47
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 45

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

#freezeObject

:nodoc:



49
50
51
52
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 49

def freeze #:nodoc:
  quantifier.freeze if quantifier
  super
end

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


17
18
19
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 17

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

#match(char) ⇒ Object



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

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

#option_namesObject



10
11
12
# File 'lib/rack/mount/vendor/reginald/reginald/character.rb', line 10

def option_names
  %w( quantifier ) + super
end

#to_regexpObject



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

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

#to_s(parent = false) ⇒ Object



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

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