Class: REXML::Validation::State

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

Direct Known Subclasses

Choice, OneOrMore, Optional, Sequence

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ State

Returns a new instance of State.



127
128
129
130
131
132
133
134
# File 'lib/rexml/validation/relaxng.rb', line 127

def initialize( context )
  @previous = []
  @events = []
  @current = 0
  @count = context.count += 1
  @references = context.references
  @value = false
end

Instance Method Details

#<<(event) ⇒ Object



191
192
193
# File 'lib/rexml/validation/relaxng.rb', line 191

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

#expectedObject



187
188
189
# File 'lib/rexml/validation/relaxng.rb', line 187

def expected
  return [@events[@current]]
end

#inspectObject



180
181
182
183
184
185
# File 'lib/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) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/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) ⇒ Object



142
143
144
# File 'lib/rexml/validation/relaxng.rb', line 142

def previous=( previous )
  @previous << previous
end

#resetObject



136
137
138
139
140
# File 'lib/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_sObject



172
173
174
175
176
177
178
# File 'lib/rexml/validation/relaxng.rb', line 172

def to_s
  # Abbreviated:
  self.class.name =~ /(?:::)(\w)\w+$/
  # Full:
  #self.class.name =~ /(?:::)(\w+)$/
  "#$1.#@count"
end