Class: Strling::Core::CharClass

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

Overview

Represents a character class.

Matches any character from the set defined by items. Can be negated to match any character NOT in the set.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(negated, items) ⇒ CharClass

Returns a new instance of CharClass.

Parameters:

  • negated (Boolean)

    Whether the class is negated

  • items (Array<ClassItem>)

    The items in the character class



293
294
295
296
# File 'lib/strling/core/nodes.rb', line 293

def initialize(negated, items)
  @negated = negated
  @items = items
end

Instance Attribute Details

#itemsArray<ClassItem>

Returns The items in the character class.

Returns:

  • (Array<ClassItem>)

    The items in the character class



289
290
291
# File 'lib/strling/core/nodes.rb', line 289

def items
  @items
end

#negatedBoolean

Returns Whether the class is negated.

Returns:

  • (Boolean)

    Whether the class is negated



286
287
288
# File 'lib/strling/core/nodes.rb', line 286

def negated
  @negated
end

Instance Method Details

#to_dictObject



298
299
300
301
302
303
304
# File 'lib/strling/core/nodes.rb', line 298

def to_dict
  {
    'kind' => 'CharClass',
    'negated' => negated,
    'items' => items.map(&:to_dict)
  }
end