Class: REXML::Validation::State (Ruby 2.3.2)
Description: Class : REXML::Validation::State - Ruby 2.3.2

- Home
- Core 2.3.2
- Std-lib 2.3.2
- Downloads

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

### Home Classes Methods

### In Files

- rexml/validation/relaxng.rb

### Parent

Object

### Methods

- ::new
- #<<
- #add_event_to_arry
- #expand_ref_in
- #expected
- #generate_event
- #inspect
- #next
- #previous=
- #reset
- #to_s

### 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::State

### Public Class Methods

new( context ) click to toggle source

                   # File rexml/validation/relaxng.rb, line 127
    def initialize( context )
      @previous = []
      @events = []
      @current = 0
      @count = context.count += 1
      @references = context.references
      @value = false
    end

### Public Instance Methods

<<( event ) click to toggle source

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

expected() click to toggle source

                   # File rexml/validation/relaxng.rb, line 187
    def expected
      return [@events[@current]]
    end

inspect() click to toggle source

                   # File rexml/validation/relaxng.rb, line 180
    def inspect
      "< #{to_s} #{@events.collect{|e|
        pre = e == @events[@current] ? '#' : ''
        pre + e.inspect unless self == e
      }.join(', ')} >"
    end

next( event ) click to toggle source

                   # File rexml/validation/relaxng.rb, line 146
    def next( event )
      #print "In next with #{event.inspect}.  "
      #p @previous
      return @previous.pop.next( event ) if @events[@current].nil?
      expand_ref_in( @events, @current ) if @events[@current].class == Ref
      if ( @events[@current].kind_of? State )
        @current += 1
        @events[@current-1].previous = self
        return @events[@current-1].next( event )
      end
      if ( @events[@current].matches?(event) )
        @current += 1
        if @events[@current].nil?
          return @previous.pop
        elsif @events[@current].kind_of? State
          @current += 1
          @events[@current-1].previous = self
          return @events[@current-1]
        else
          return self
        end
      else
        return nil
      end
    end

previous=( previous ) click to toggle source

                   # File rexml/validation/relaxng.rb, line 142
    def previous=( previous )
      @previous << previous
    end

reset() click to toggle source

                   # File rexml/validation/relaxng.rb, line 136
    def reset
      return if @current == 0
      @current = 0
      @events.each {|s| s.reset if s.kind_of? State }
    end

to_s() click to toggle source

                   # File rexml/validation/relaxng.rb, line 172
    def to_s
      # Abbreviated:
      self.class.name =~ /(?:::)(\w)\w+$/
      # Full:
      #self.class.name =~ /(?:::)(\w+)$/
      "#$1.#@count"
    end

### Protected Instance Methods

add_event_to_arry( arry, evt ) click to toggle source

                   # File rexml/validation/relaxng.rb, line 205
    def add_event_to_arry( arry, evt )
      evt = generate_event( evt )
      if evt.kind_of? String
        arry[-1].event_arg = evt if arry[-1].kind_of? Event and @value
        @value = false
      else
        arry << evt
      end
    end

expand_ref_in( arry, ind ) click to toggle source

                   # File rexml/validation/relaxng.rb, line 197
    def expand_ref_in( arry, ind )
      new_events = []
      @references[ arry[ind].to_s ].each{ |evt|
        add_event_to_arry(new_events,evt)
      }
      arry[ind,1] = new_events
    end

generate_event( event ) click to toggle source

                   # File rexml/validation/relaxng.rb, line 215
    def generate_event( event )
      return event if event.kind_of? State or event.class == Ref
      evt = nil
      arg = nil
      case event[0]
      when :start_element
        case event[1]
        when "element"
          evt = :start_element
          arg = event[2]["name"]
        when "attribute"
          evt = :start_attribute
          arg = event[2]["name"]
        when "text"
          evt = :text
        when "value"
          evt = :text
          @value = true
        end
      when :text
        return event[1]
      when :end_document
        return Event.new( event[0] )
      else # then :end_element
        case event[1]
        when "element"
          evt = :end_element
        when "attribute"
          evt = :end_attribute
        end
      end
      return Event.new( evt, arg )
    end