Sha256: 06364b9eb58974f450d9fd0703fd6b175ab264f0b9f14e87893e1dca620b9101

Contents?: true

Size: 514 Bytes

Versions: 11

Compression:

Stored size: 514 Bytes

Contents

module Temple
  module Filters
    # Erase expressions with a certain type
    #
    # @api public
    class Eraser < Filter
      # [] is the empty type => keep all
      define_options :keep => [[]], :erase => nil

      def compile(exp)
        exp.first == :multi || (do?(:keep, exp) && !do?(:erase, exp)) ?
          super(exp) : [:multi]
      end

      protected

      def do?(list, exp)
        options[list].to_a.map {|type| [*type] }.any? {|type| exp[0,type.size] == type }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
temple-0.6.10 lib/temple/filters/eraser.rb
temple-0.6.9 lib/temple/filters/eraser.rb
temple-0.6.8 lib/temple/filters/eraser.rb
temple-0.6.7 lib/temple/filters/eraser.rb
temple-0.6.6 lib/temple/filters/eraser.rb
temple-0.6.5 lib/temple/filters/eraser.rb
temple-0.6.4 lib/temple/filters/eraser.rb
temple-0.6.3 lib/temple/filters/eraser.rb
temple-0.6.0 lib/temple/filters/eraser.rb
temple-0.5.5 lib/temple/filters/eraser.rb
temple-0.5.4 lib/temple/filters/eraser.rb