Class: Regexp::Expression::Quantifier

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/regexp_parser/expression/quantifier.rb

Overview

TODO: in v3.0.0, maybe put Shared back into Base, and inherit from Base and call super in #initialize, but raise in #quantifier= and #quantify, or introduce an Expression::Quantifiable intermediate class. Or actually allow chaining as a more concise but tricky solution than PR#69.

Constant Summary collapse

MODES =
%i[greedy possessive reluctant]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shared

#==, #base_length, #coded_offset, #full_length, #human_name, included, #initialize_copy, #is?, #nesting_level=, #offset, #one_of?, #optional?, #parts, #quantified?, #quantifier=, #quantifier_affix, #referential?, #starts_at, #terminal?, #to_s, #token_class, #type?

Constructor Details

#initialize(*args) ⇒ Quantifier

Returns a new instance of Quantifier.



13
14
15
16
17
18
19
20
21
# File 'lib/regexp_parser/expression/quantifier.rb', line 13

def initialize(*args)
  deprecated_old_init(*args) and return if args.count == 4 || args.count == 5

  init_from_token_and_options(*args)
  @mode = (token.to_s[/greedy|reluctant|possessive/] || :greedy).to_sym
  @min, @max = minmax
  # TODO: remove in v3.0.0, stop removing parts of #token (?)
  self.token = token.to_s.sub(/_(greedy|possessive|reluctant)/, '').to_sym
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



11
12
13
# File 'lib/regexp_parser/expression/quantifier.rb', line 11

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



11
12
13
# File 'lib/regexp_parser/expression/quantifier.rb', line 11

def min
  @min
end

#modeObject (readonly)

Returns the value of attribute mode.



11
12
13
# File 'lib/regexp_parser/expression/quantifier.rb', line 11

def mode
  @mode
end

Instance Method Details

#to_hObject



23
24
25
26
27
28
29
30
31
# File 'lib/regexp_parser/expression/quantifier.rb', line 23

def to_h
  {
    token: token,
    text:  text,
    mode:  mode,
    min:   min,
    max:   max,
  }
end