Class Uttk::Filters::NodeCut
In: lib/uttk/filters/NodeCut.rb
Parent: KeepSkipBased

FIXME Can be path based This filter cut nodes which match `keep’ but not `skip‘

  options:
      keep:  A regular expression (all keys which match this regexp are cut)
      skip:  Antoher regexp that skip keys which match
      prune: Completly cut all sub nodes of a cut one

Methods

new   new_node   notif   prune?   pruning_path?   up  

Included Modules

Concrete

Classes and Modules

Module Uttk::Filters::NodeCut::Assertions

Public Class methods

[Source]

# File lib/uttk/filters/NodeCut.rb, line 22
      def initialize ( *a, &b )
        super
        @pruning_path = Set.new
        @pruning_path_node = nil
      end

Public Instance methods

[Source]

# File lib/uttk/filters/NodeCut.rb, line 68
      def prune?
        @options[:prune]
      end

[Source]

# File lib/uttk/filters/NodeCut.rb, line 73
      def pruning_path? ( path )
        return false unless @pruning_path_node
        @pruning_path_node.each_with_index do |seg, i|
          return false if seg != path[i]
        end
        return true
      end

Protected Instance methods

[Source]

# File lib/uttk/filters/NodeCut.rb, line 29
      def new_node ( path, node )
        if @pruning_path_node or keep? node.segment
          super
        elsif prune?
          @pruning_path << path.to_s
          @pruning_path_node = path.dup << node
        else
          @pruning_path << path.to_s
        end
      end

[Source]

# File lib/uttk/filters/NodeCut.rb, line 55
      def notif ( msg, *args )
        return super if args.first.nil?
        path = args.shift
        return if pruning_path? path
        copy = path.dup
        copy.delete_if do |x|
          skip? x.segment
        end
        super(msg, copy, *args)
      end

[Source]

# File lib/uttk/filters/NodeCut.rb, line 42
      def up ( path )
        node = path.last
        path_s= path.to_s
        if @pruning_path.include? path_s
          @pruning_path_node = nil
          @pruning_path.delete path_s
        else
          super
        end
      end

[Validate]