Class: REXML::Validation::OneOrMore

Inherits:
State show all
Defined in:
lib/extensions/rexml/rexml/validation/relaxng.rb

Instance Method Summary collapse

Methods inherited from State

#<<, #inspect, #previous=, #to_s

Constructor Details

#initialize(context) ⇒ OneOrMore

Returns a new instance of OneOrMore.



316
317
318
319
# File 'lib/extensions/rexml/rexml/validation/relaxng.rb', line 316

def initialize context
  super
  @ord = 0
end

Instance Method Details

#expectedObject



352
353
354
355
356
357
358
# File 'lib/extensions/rexml/rexml/validation/relaxng.rb', line 352

def expected
  if @current == 0 and @ord > 0
    return [@previous[-1].expected, @events[0]].flatten
  else
    return [@events[@current]]
  end
end

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


347
348
349
350
# File 'lib/extensions/rexml/rexml/validation/relaxng.rb', line 347

def matches?( event )
  @events[@current].matches?(event) || 
  (@current == 0 and @ord > 0 and @previous[-1].matches?(event))
end

#next(event) ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/extensions/rexml/rexml/validation/relaxng.rb', line 326

def next( event )
  expand_ref_in( @events, @current ) if @events[@current].class == Ref
  if ( @events[@current].matches?(event) )
    @current += 1
    @ord += 1
    if @events[@current].nil?
      @current = 0
      return self
    elsif @events[@current].kind_of? State
      @current += 1
      @events[@current-1].previous = self
      return @events[@current-1]
    else
      return self
    end
  else
    return @previous.pop.next( event ) if @current == 0 and @ord > 0
    return nil
  end
end

#resetObject



321
322
323
324
# File 'lib/extensions/rexml/rexml/validation/relaxng.rb', line 321

def reset
  super 
  @ord = 0
end