Class: Strling::Core::Group

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

Overview

Represents a capturing or non-capturing group.

Groups pattern elements together and optionally captures the matched text for later reference.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capturing, body, name: nil, atomic: nil) ⇒ Group

Returns a new instance of Group.

Parameters:

  • capturing (Boolean)

    Whether the group is capturing

  • body (Node)

    The body of the group

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

    The name of the group

  • atomic (Boolean, nil) (defaults to: nil)

    Whether the group is atomic



367
368
369
370
371
372
# File 'lib/strling/core/nodes.rb', line 367

def initialize(capturing, body, name: nil, atomic: nil)
  @capturing = capturing
  @body = body
  @name = name
  @atomic = atomic
end

Instance Attribute Details

#atomicBoolean?

Returns Whether the group is atomic (extension).

Returns:

  • (Boolean, nil)

    Whether the group is atomic (extension)



361
362
363
# File 'lib/strling/core/nodes.rb', line 361

def atomic
  @atomic
end

#bodyNode

Returns The body of the group.

Returns:

  • (Node)

    The body of the group



355
356
357
# File 'lib/strling/core/nodes.rb', line 355

def body
  @body
end

#capturingBoolean

Returns Whether the group is capturing.

Returns:

  • (Boolean)

    Whether the group is capturing



352
353
354
# File 'lib/strling/core/nodes.rb', line 352

def capturing
  @capturing
end

#nameString?

Returns The name of the group (for named captures).

Returns:

  • (String, nil)

    The name of the group (for named captures)



358
359
360
# File 'lib/strling/core/nodes.rb', line 358

def name
  @name
end

Instance Method Details

#to_dictObject



374
375
376
377
378
379
380
381
382
383
# File 'lib/strling/core/nodes.rb', line 374

def to_dict
  data = {
    'kind' => 'Group',
    'capturing' => capturing,
    'body' => body.to_dict
  }
  data['name'] = name unless name.nil?
  data['atomic'] = atomic unless atomic.nil?
  data
end