Class: Regin::Character

Inherits:
Atom
  • Object
show all
Defined in:
lib/rack/mount/vendor/regin/regin/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/regin/regin/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/regin/regin/character.rb', line 3

def quantifier
  @quantifier
end

Instance Method Details

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


47
48
49
# File 'lib/rack/mount/vendor/regin/regin/character.rb', line 47

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

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/rack/mount/vendor/regin/regin/character.rb', line 39

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/regin/regin/character.rb', line 17

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

#match(char) ⇒ Object



35
36
37
# File 'lib/rack/mount/vendor/regin/regin/character.rb', line 35

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

#option_namesObject



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

def option_names
  %w( quantifier ) + super
end

#to_regexp(anchored = false) ⇒ Object



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

def to_regexp(anchored = false)
  re = to_s(true)
  re = "\\A#{re}\\Z" if anchored
  Regexp.compile(re, ignorecase)
end

#to_s(parent = false) ⇒ Object



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

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