Class: RegExpr::Repeat
Overview
/VALUEMIN,MAX/
Constant Summary collapse
- SimpleChar =
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Attributes inherited from Segment
Instance Method Summary collapse
-
#initialize(value, min = 1, max = min) ⇒ Repeat
constructor
A new instance of Repeat.
- #minandmax(x) ⇒ Object
- #optimize ⇒ Object
- #to_r ⇒ Object
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
#max ⇒ Object (readonly)
Returns the value of attribute max.
262 263 264 |
# File 'lib/regexpr.rb', line 262 def max @max end |
#min ⇒ Object (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 |
#optimize ⇒ Object
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_r ⇒ Object
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 |