Sha256: e3363be61920900f8a27f88786d0ba81b086538bd1dfe8e2712c899521d83370

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Pacer
  module Pipes
    class SimpleVisitorPipe < Pacer::Pipes::RubyPipe
      attr_reader :visitor, :in_section

      attr_accessor :use_on_element, :use_after_element, :use_reset

      def initialize(visitor = nil)
        super()
        self.visitor = visitor if visitor
        @in_section = false
      end

      def visitor=(visitor)
        @visitor = visitor
        @use_on_element      = visitor.respond_to? :on_element
        @use_after_element   = visitor.respond_to? :after_element
        @use_reset           = visitor.respond_to? :reset
      end

      def processNextStart
        visitor.after_element if use_after_element and in_section
        current = starts.next
        @in_section = true unless in_section
        visitor.on_element(current) if use_on_element
        return current
      rescue NativeException => e
        if e.cause.getClass == Pacer::NoSuchElementException.getClass
          @in_section = false
          raise e.cause
        else
          raise
        end
      end

      def reset
        visitor.reset if use_reset
        @in_section = false
        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pacer-0.9.1.1-java lib/pacer/pipe/simple_visitor_pipe.rb