Sha256: 1bb10986f6d6dbb1e5ae1f02703059cc1b4d2711d4f04cd6b87866eb17031951

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

require_relative 's9api'

module Saxon
  # An iterator across an XPath axis of an XDM document, e.g. down to children
  # (+child+), up to the root (+ancestor+)
  # @example iterate over child nodes
  #   AxisIterator.new(node, :child).each do |child_node|
  #     puts child_node.node_name
  #   end
  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

    # yields each node in the sequence
    # @yieldparam [Saxon::XDM::Node] the next node in the sequence
    def each(&block)
      s9_sequence_iterator.lazy.map { |s9_xdm_node| Saxon::XDM::Node.new(s9_xdm_node) }.each(&block)
    end

    private

    def s9_sequence_iterator
      s9_xdm_node.axisIterator(s9_axis)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
saxon-rb-0.8.3-java lib/saxon/axis_iterator.rb
saxon-rb-0.8.2-java lib/saxon/axis_iterator.rb
saxon-rb-0.8.1-java lib/saxon/axis_iterator.rb
saxon-rb-0.8.0-java lib/saxon/axis_iterator.rb
saxon-rb-0.7.3-java lib/saxon/axis_iterator.rb
saxon-rb-0.7.2-java lib/saxon/axis_iterator.rb
saxon-rb-0.7.1-java lib/saxon/axis_iterator.rb
saxon-rb-0.7.0-java lib/saxon/axis_iterator.rb
saxon-rb-0.6.0-java lib/saxon/axis_iterator.rb
saxon-rb-0.5.0-java lib/saxon/axis_iterator.rb