Class: REXML::Validation::State
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | lib/rexml/validation/relaxng.rb |
Class Method Summary
- .new(context) ⇒ State constructor
Instance Attribute Summary
- #previous=(previous) writeonly
Instance Method Summary
- #<<(event)
- #expected
- #inspect
- #next(event)
- #reset
- #to_s
- #add_event_to_arry(arry, evt) protected
- #expand_ref_in(arry, ind) protected
- #generate_event(event) protected
Constructor Details
.new(context) ⇒ State
# File 'lib/rexml/validation/relaxng.rb', line 128
def initialize( context ) @previous = [] @events = [] @current = 0 @count = context.count += 1 @references = context.references @value = false end
Instance Attribute Details
#previous=(previous) (writeonly)
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 143
def previous=( previous ) @previous << previous end
Instance Method Details
#<<(event)
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 192
def <<( event ) add_event_to_arry( @events, event ) end
#add_event_to_arry(arry, evt) (protected)
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 206
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) (protected)
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 198
def ( arry, ind ) new_events = [] @references[ arry[ind].to_s ].each{ |evt| add_event_to_arry(new_events,evt) } arry[ind,1] = new_events end
#expected
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 188
def expected return [@events[@current]] end
#generate_event(event) (protected)
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 216
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
#inspect
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 181
def inspect "< #{to_s} #{@events.collect{|e| pre = e == @events[@current] ? '#' : '' pre + e.inspect unless self == e }.join(', ')} >" end
#next(event)
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 147
def next( event ) #print "In next with #{event.inspect}. " #p @previous return @previous.pop.next( event ) if @events[@current].nil? ( @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
#reset
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 137
def reset return if @current == 0 @current = 0 @events.each {|s| s.reset if s.kind_of? State } end
#to_s
[ GitHub ]# File 'lib/rexml/validation/relaxng.rb', line 173
def to_s # Abbreviated: self.class.name =~ /(?:::)(\w)\w+$/ # Full: #self.class.name =~ /(?:::)(\w+)$/ "#$1.#@count" end