soulcutter/saxerator

View on GitHub
lib/saxerator/latches/at_depth.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Saxerator
  module Latches
    class AtDepth < ::Saxerator::SaxHandler
      def initialize(depth)
        @target_depth = depth
        @current_depth = -1
      end

      def start_element(_, __)
        @current_depth += 1
      end

      def end_element(_)
        @current_depth -= 1
      end

      def open?
        @current_depth == @target_depth
      end
    end
  end
end