Class: RegExpr::Repeat

Inherits:
Segment show all
Defined in:
lib/regexpr.rb

Overview

/VALUEMIN,MAX/

Constant Summary collapse

SimpleChar =

Instance Attribute Summary collapse

Attributes inherited from Segment

#value

Instance Method Summary collapse

Methods inherited from Segment

deepest, #empty?, #names, nooptimize, novalue, optimize

Constructor Details

#initialize(value, min = 1, max = min) ⇒ Repeat

Returns a new instance of Repeat.



277
278
279
280
# File 'lib/regexpr.rb', line 277

def initialize value, min= 1, max= min
	super value
	@min, @max= self.minandmax( min), self.minandmax( max)
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



262
263
264
# File 'lib/regexpr.rb', line 262

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



262
263
264
# File 'lib/regexpr.rb', line 262

def min
  @min
end

Instance Method Details

#minandmax(x) ⇒ Object



264
265
266
267
268
269
# File 'lib/regexpr.rb', line 264

def minandmax x
	case x
	when nil, ''  then nil
	else x.to_i
	end
end

#optimizeObject



271
272
273
274
275
# File 'lib/regexpr.rb', line 271

def optimize
	super
	r = (min == 1 and max == 1) ? @value : self
	r
end

#to_rObject



282
283
284
285
286
# File 'lib/regexpr.rb', line 282

def to_r
	t= '{%s,%s}'% [ @min||'', @max||'' ]
	return ''  if '{0,0}' == t
	@value.to_r+ (SimpleChar[ t] || t)
end