Class: Strling::Core::Backref

Inherits:
Node
  • Object
show all
Defined in:
lib/strling/core/nodes.rb

Overview

Represents a backreference.

Matches the same text as previously captured by a group, referenced either by index or by name.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(by_index: nil, by_name: nil) ⇒ Backref

Returns a new instance of Backref.

Parameters:

  • by_index (Integer, nil) (defaults to: nil)

    The group index to reference

  • by_name (String, nil) (defaults to: nil)

    The group name to reference



399
400
401
402
# File 'lib/strling/core/nodes.rb', line 399

def initialize(by_index: nil, by_name: nil)
  @by_index = by_index
  @by_name = by_name
end

Instance Attribute Details

#by_indexInteger?

Returns The group index to reference.

Returns:

  • (Integer, nil)

    The group index to reference



392
393
394
# File 'lib/strling/core/nodes.rb', line 392

def by_index
  @by_index
end

#by_nameString?

Returns The group name to reference.

Returns:

  • (String, nil)

    The group name to reference



395
396
397
# File 'lib/strling/core/nodes.rb', line 395

def by_name
  @by_name
end

Instance Method Details

#to_dictObject



404
405
406
407
408
409
# File 'lib/strling/core/nodes.rb', line 404

def to_dict
  data = { 'kind' => 'Backref' }
  data['byIndex'] = by_index unless by_index.nil?
  data['byName'] = by_name unless by_name.nil?
  data
end