Class: List::Matcher::SymbolPattern

Inherits:
Node
  • Object
show all
Defined in:
lib/list_matcher.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#engine, #optional, #root, #symbols

Instance Method Summary collapse

Methods inherited from Node

#bound, #children, #finalize, #flatten, #optional?, #pfx, #qmark, #quote, #root?, #wrap

Constructor Details

#initialize(engine, char, var, pat, atomic: (var.is_a?(Regexp) && pat.nil?), left: nil, right: nil) ⇒ SymbolPattern

Returns a new instance of SymbolPattern.



523
524
525
526
527
528
529
530
531
532
# File 'lib/list_matcher.rb', line 523

def initialize(engine, char, var, pat, atomic: (var.is_a?(Regexp) && pat.nil?), left: nil, right: nil)
  super(engine, nil)
  @char   = char
  @symbol = var.to_s
  @var    = var.is_a?(String) || var.is_a?(Symbol) ? Regexp.new(Regexp.quote(var.to_s)) : var
  @pat    = pat || var.to_s
  @atomic = !!atomic
  @left   = left
  @right  = right
end

Instance Attribute Details

#charObject

Returns the value of attribute char.



522
523
524
# File 'lib/list_matcher.rb', line 522

def char
  @char
end

#leftObject

Returns the value of attribute left.



522
523
524
# File 'lib/list_matcher.rb', line 522

def left
  @left
end

#patObject

Returns the value of attribute pat.



522
523
524
# File 'lib/list_matcher.rb', line 522

def pat
  @pat
end

#rightObject

Returns the value of attribute right.



522
523
524
# File 'lib/list_matcher.rb', line 522

def right
  @right
end

#symbolObject

Returns the value of attribute symbol.



522
523
524
# File 'lib/list_matcher.rb', line 522

def symbol
  @symbol
end

#varObject

Returns the value of attribute var.



522
523
524
# File 'lib/list_matcher.rb', line 522

def var
  @var
end

Instance Method Details

#atomic?Boolean

Returns:

  • (Boolean)


538
539
540
# File 'lib/list_matcher.rb', line 538

def atomic?
  @atomic
end

#convertObject



546
547
548
549
# File 'lib/list_matcher.rb', line 546

def convert
  rx = @pat
  finalize rx
end

#dupObject



534
535
536
# File 'lib/list_matcher.rb', line 534

def dup
  self.class.new engine, char, var, pat, atomic: atomic?, left: left, right: right
end

#optionalize(bool) ⇒ Object



551
552
553
554
555
556
557
558
# File 'lib/list_matcher.rb', line 551

def optionalize(bool)
  n = self
  if bool
    n = n.dup
    n.optional = bool
  end
  n
end

#to_sObject



542
543
544
# File 'lib/list_matcher.rb', line 542

def to_s
  self.char
end