Class: Regexgen::Ast::CharClass

Inherits:
Object
  • Object
show all
Defined in:
lib/regexgen/ast.rb

Overview

Represents a character class (e.g. [0-9a-z])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b) ⇒ CharClass

Returns a new instance of CharClass.



35
36
37
38
# File 'lib/regexgen/ast.rb', line 35

def initialize(a, b)
  @precedence = 1
  @set = [a, b].flatten
end

Instance Attribute Details

#precedenceObject (readonly)

Returns the value of attribute precedence.



33
34
35
# File 'lib/regexgen/ast.rb', line 33

def precedence
  @precedence
end

Instance Method Details

#char_classObject



56
57
58
# File 'lib/regexgen/ast.rb', line 56

def char_class
  @set
end

#lengthObject



40
41
42
# File 'lib/regexgen/ast.rb', line 40

def length
  1
end

#single_character?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/regexgen/ast.rb', line 44

def single_character?
  @set.none? { |c| c.ord > 0xffff }
end

#single_codepoint?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/regexgen/ast.rb', line 48

def single_codepoint?
  true
end

#to_sObject



52
53
54
# File 'lib/regexgen/ast.rb', line 52

def to_s
  "[#{to_ranges_string}]"
end