Sha256: 813c13725a5e38fceccf310e1adfe6129e8a0c3578fcb7acb9fb5bf7c48ba917

Contents?: true

Size: 830 Bytes

Versions: 4

Compression:

Stored size: 830 Bytes

Contents

require 'saxon/s9api'
require 'saxon/xdm_node'

module Saxon
  # An XPath Data Model Node object, representing an XML document, or an element or one of the other node chunks in the XDM.
  class AxisIterator
    include Enumerable

    attr_reader :s9_xdm_node, :s9_axis
    private :s9_xdm_node, :s9_axis

    def initialize(xdm_node, axis)
      @s9_xdm_node = xdm_node.to_java
      @s9_axis = Saxon::S9API::Axis.const_get(axis.to_s.upcase.to_sym)
    end

    # @return [Saxon::S9API::XdmSequenceIterator] A new Saxon Java XDM sequence iterator.
    def to_java
      s9_sequence_iterator
    end

    def each(&block)
      s9_sequence_iterator.lazy.map { |s9_xdm_node| Saxon::XdmNode.new(s9_xdm_node) }.each(&block)
    end

    private

    def s9_sequence_iterator
      s9_xdm_node.axisIterator(s9_axis)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
saxon-0.2.2-java lib/saxon/axis_iterator.rb
saxon-0.2.1-java lib/saxon/axis_iterator.rb
saxon-0.2.0-java lib/saxon/axis_iterator.rb
saxon-0.1.0-java lib/saxon/axis_iterator.rb