Class: Strling::Core::ClassEscape

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

Overview

Represents an escape sequence in a character class.

Matches predefined character classes (d, w, s, etc.) or Unicode property escapes (p…, P…).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, property: nil) ⇒ ClassEscape

Returns a new instance of ClassEscape.

Parameters:

  • type (String)

    The escape type

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

    The Unicode property name



268
269
270
271
# File 'lib/strling/core/nodes.rb', line 268

def initialize(type, property: nil)
  @type = type
  @property = property
end

Instance Attribute Details

#propertyString?

Returns The Unicode property name (for p and P).

Returns:

  • (String, nil)

    The Unicode property name (for p and P)



264
265
266
# File 'lib/strling/core/nodes.rb', line 264

def property
  @property
end

#typeString

Returns The escape type (d, D, w, W, s, S, p, P).

Returns:

  • (String)

    The escape type (d, D, w, W, s, S, p, P)



261
262
263
# File 'lib/strling/core/nodes.rb', line 261

def type
  @type
end

Instance Method Details

#to_dictObject



273
274
275
276
277
# File 'lib/strling/core/nodes.rb', line 273

def to_dict
  data = { 'kind' => 'Esc', 'type' => type }
  data['property'] = property if %w[p P].include?(type) && property
  data
end