Class: REXML::Validation::Choice
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
State
|
|
Instance Chain:
self,
State
|
|
Inherits: |
REXML::Validation::State
|
Defined in: | lib/rexml/validation/relaxng.rb |
Class Method Summary
Instance Attribute Summary
State - Inherited
Instance Method Summary
- #<<(event)
- #expected
- #inspect
- #matches?(event) ⇒ Boolean
- #next(event)
- #reset
- #add_event_to_arry(arry, evt) protected
State - Inherited
Constructor Details
.new(context) ⇒ Choice
# File 'lib/rexml/validation/relaxng.rb', line 358
def initialize context super @choices = [] end
Instance Method Details
#<<(event)
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 369
def <<( event ) add_event_to_arry( @choices, event ) end
#add_event_to_arry(arry, evt) (protected)
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 419
def add_event_to_arry( arry, evt ) if evt.kind_of? State or evt.class == Ref arry << [evt] elsif evt[0] == :text if arry[-1] and arry[-1][-1].kind_of?( Event ) and arry[-1][-1].event_type == :text and @value arry[-1][-1].event_arg = evt[1] @value = false end else arry << [] if evt[0] == :start_element arry[-1] << generate_event( evt ) end end
#expected
[ GitHub ]# 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
#inspect
[ GitHub ]# 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
# 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)
[ GitHub ]# 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 ( @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
#reset
[ GitHub ]# 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