Class: REXML::Validation::Choice

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

Direct Known Subclasses

Interleave

Instance Method Summary collapse

Methods inherited from State

#previous=, #to_s

Constructor Details

#initialize(context) ⇒ Choice

Returns a new instance of Choice.



358
359
360
361
# File 'lib/rexml/validation/relaxng.rb', line 358

def initialize context
  super
  @choices = []
end

Instance Method Details

#<<(event) ⇒ Object



369
370
371
# File 'lib/rexml/validation/relaxng.rb', line 369

def <<( event )
  add_event_to_arry( @choices, event )
end

#expectedObject



403
404
405
406
407
408
409
410
411
412
# File 'lib/rexml/validation/relaxng.rb', line 403

def expected
  return [@events[@current]] if @events.size > 0
  return @choices.collect do |x|
    if x[0].kind_of? State
      x[0].expected
    else
      x[0]
    end
  end.flatten
end

#inspectObject



414
415
416
# File 'lib/rexml/validation/relaxng.rb', line 414

def inspect
  "< #{to_s} #{@choices.collect{|e| e.collect{|f|f.to_s}.join(', ')}.join(' or ')} >"
end

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


398
399
400
401
# File 'lib/rexml/validation/relaxng.rb', line 398

def matches?( event )
  return @events[@current].matches?( event ) if @events.size > 0
  !@choices.find{|evt| evt[0].matches?(event)}.nil?
end

#next(event) ⇒ Object



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/rexml/validation/relaxng.rb', line 373

def next( event )
  # Make the choice if we haven't
  if @events.size == 0
    c = 0 ; max = @choices.size
    while c < max
      if @choices[c][0].class == Ref
        expand_ref_in( @choices[c], 0 )
        @choices += @choices[c]
        @choices.delete( @choices[c] )
        max -= 1
      else
        c += 1
      end
    end
    @events = @choices.find { |evt| evt[0].matches? event }
    # Remove the references
    # Find the events
  end
  unless @events
    @events = []
    return nil
  end
  super
end

#resetObject



363
364
365
366
367
# File 'lib/rexml/validation/relaxng.rb', line 363

def reset
  super
  @events = []
  @choices.each { |c| c.each { |s| s.reset if s.kind_of? State } }
end