Class: REXML::Validation::Choice (Ruby 2.3.7)
Description: Class : REXML::Validation::Choice - Ruby 2.3.7

- Home
- Core 2.3.7
- Std-lib 2.3.7
- Downloads

Support for the Ruby 2.3 series has ended. See here for reference.

### Home Classes Methods

### In Files

- rexml/validation/relaxng.rb

### Parent

REXML::Validation::State

### Methods

- ::new
- #<<
- #add_event_to_arry
- #expected
- #inspect
- #matches?
- #next
- #reset

### Class/Module Index

Quicksearch

- Array
- Fixnum
- Float
- Object
- REXML
- REXML::AttlistDecl
- REXML::Attribute
- REXML::Attributes
- REXML::CData
- REXML::Child
- REXML::Comment
- REXML::DTD
- REXML::DTD::AttlistDecl
- REXML::DTD::ElementDecl
- REXML::DTD::EntityDecl
- REXML::DTD::NotationDecl
- REXML::DTD::Parser
- REXML::Declaration
- REXML::DocType
- REXML::Document
- REXML::Element
- REXML::ElementDecl
- REXML::Elements
- REXML::Encoding
- REXML::Entity
- REXML::EntityConst
- REXML::ExternalEntity
- REXML::Formatters
- REXML::Formatters::Default
- REXML::Formatters::Pretty
- REXML::Formatters::Transitive
- REXML::Functions
- REXML::IOSource
- REXML::Instruction
- REXML::Light
- REXML::Light::Node
- REXML::Namespace
- REXML::Node
- REXML::NotationDecl
- REXML::Output
- REXML::Parent
- REXML::ParseException
- REXML::Parsers
- REXML::Parsers::BaseParser
- REXML::Parsers::LightParser
- REXML::Parsers::PullEvent
- REXML::Parsers::PullParser
- REXML::Parsers::SAX2Parser
- REXML::Parsers::StreamParser
- REXML::Parsers::TreeParser
- REXML::Parsers::UltraLightParser
- REXML::Parsers::XPathParser
- REXML::QuickPath
- REXML::SAX2Listener
- REXML::Security
- REXML::Source
- REXML::SourceFactory
- REXML::StreamListener
- REXML::SyncEnumerator
- REXML::Text
- REXML::UndefinedNamespaceException
- REXML::Validation
- REXML::Validation::Choice
- REXML::Validation::Event
- REXML::Validation::Interleave
- REXML::Validation::OneOrMore
- REXML::Validation::Optional
- REXML::Validation::Ref
- REXML::Validation::RelaxNG
- REXML::Validation::Sequence
- REXML::Validation::State
- REXML::Validation::ValidationException
- REXML::Validation::Validator
- REXML::Validation::ZeroOrMore
- REXML::XMLDecl
- REXML::XMLTokens
- REXML::XPath
- REXML::XPathParser
- Symbol

No matching classes.

# REXML::Validation::Choice

### Public Class Methods

new(context) click to toggle source

                   # File rexml/validation/relaxng.rb, line 358
    def initialize context
      super
      @choices = []
    end

### Public Instance Methods

<<( event ) click to toggle source

                   # File rexml/validation/relaxng.rb, line 369
    def <<( event )
      add_event_to_arry( @choices, event )
    end

expected() click to toggle source

                   # File 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() click to toggle source

                   # File 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 ) click to toggle source

                   # File 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 ) click to toggle source

                   # File 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

reset() click to toggle source

                   # File rexml/validation/relaxng.rb, line 363
    def reset
      super
      @events = []
      @choices.each { |c| c.each { |s| s.reset if s.kind_of? State } }
    end

### Protected Instance Methods

add_event_to_arry( arry, evt ) click to toggle source

                   # File 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