Class: CodeRay::Encoders::TokenKindFilter

### Home Classes Methods

### In Files

- lib/coderay/encoders/token_kind_filter.rb

### Parent

CodeRay::Encoders::Filter

### Methods

- #begin_group
- #begin_line
- #end_group
- #end_line
- #include_group?
- #include_text_token?
- #setup
- #text_token

### Class/Module Index

Quicksearch

- CodeRay
- CodeRay::Duo
- CodeRay::Encoders
- CodeRay::Encoders::CommentFilter
- CodeRay::Encoders::Count
- CodeRay::Encoders::Debug
- CodeRay::Encoders::DebugLint
- CodeRay::Encoders::Div
- CodeRay::Encoders::Encoder
- CodeRay::Encoders::Filter
- CodeRay::Encoders::HTML
- CodeRay::Encoders::HTML::Output
- CodeRay::Encoders::JSON
- CodeRay::Encoders::LinesOfCode
- CodeRay::Encoders::Lint
- CodeRay::Encoders::Null
- CodeRay::Encoders::Page
- CodeRay::Encoders::Span
- CodeRay::Encoders::Statistic
- CodeRay::Encoders::Terminal
- CodeRay::Encoders::Text
- CodeRay::Encoders::TokenKindFilter
- CodeRay::Encoders::XML
- CodeRay::Encoders::YAML
- CodeRay::FileType
- CodeRay::ForRedCloth
- CodeRay::Plugin
- CodeRay::PluginHost
- CodeRay::Scanners
- CodeRay::Scanners::C
- CodeRay::Scanners::CPlusPlus
- CodeRay::Scanners::CSS
- CodeRay::Scanners::Clojure
- CodeRay::Scanners::Debug
- CodeRay::Scanners::Delphi
- CodeRay::Scanners::Diff
- CodeRay::Scanners::ERB
- CodeRay::Scanners::Go
- CodeRay::Scanners::Groovy
- CodeRay::Scanners::HAML
- CodeRay::Scanners::HTML
- CodeRay::Scanners::JSON
- CodeRay::Scanners::Java
- CodeRay::Scanners::JavaScript
- CodeRay::Scanners::Python
- CodeRay::Scanners::Raydebug
- CodeRay::Scanners::Ruby
- CodeRay::Scanners::SQL
- CodeRay::Scanners::Sass
- CodeRay::Scanners::Scanner
- CodeRay::Scanners::Taskpaper
- CodeRay::Scanners::Text
- CodeRay::Scanners::XML
- CodeRay::Scanners::YAML
- CodeRay::Styles
- CodeRay::Styles::Alpha
- CodeRay::Styles::Style
- CodeRay::Tokens
- CodeRay::TokensProxy
- CodeRay::WordList
- CodeRay::WordList::CaseIgnoring

No matching classes.

# CodeRay::Encoders::TokenKindFilter

A Filter that selects tokens based on their token kind.

## Options

### :exclude

One or many symbols (in an Array) which shall be excluded.

Default: []

### :include

One or many symbols (in an array) which shall be included.

Default: :all, which means all tokens are included.

Exclusion wins over inclusion.

See also: CommentFilter

### Constants

DEFAULT_OPTIONS

### Public Instance Methods

begin_group(kind) click to toggle source

Add the token group to the output stream if `kind` matches the conditions.

If it does not, all tokens inside the group are excluded from the stream, even if their kinds match.

    # File lib/coderay/encoders/token_kind_filter.rb, line 66
    def begin_group kind
      if @group_excluded
        @group_excluded += 1
      elsif include_group? kind
        super
      else
        @group_excluded = 1
      end
    end

begin_line(kind) click to toggle source

See `begin_group`.

    # File lib/coderay/encoders/token_kind_filter.rb, line 77
    def begin_line kind
      if @group_excluded
        @group_excluded += 1
      elsif include_group? kind
        super
      else
        @group_excluded = 1
      end
    end

end_group(kind) click to toggle source

Take care of re-enabling the delegation of tokens to the output stream if an exluded group has ended.

    # File lib/coderay/encoders/token_kind_filter.rb, line 89
    def end_group kind
      if @group_excluded
        @group_excluded -= 1
        @group_excluded = false if @group_excluded.zero?
      else
        super
      end
    end

end_line(kind) click to toggle source

See `end_group`.

    # File lib/coderay/encoders/token_kind_filter.rb, line 99
    def end_line kind
      if @group_excluded
        @group_excluded -= 1
        @group_excluded = false if @group_excluded.zero?
      else
        super
      end
    end

text_token(text, kind) click to toggle source

Add the token to the output stream if `kind` matches the conditions.

    # File lib/coderay/encoders/token_kind_filter.rb, line 57
    def text_token text, kind
      super if !@group_excluded && include_text_token?(text, kind)
    end

### Protected Instance Methods

include_group?(kind) click to toggle source

    # File lib/coderay/encoders/token_kind_filter.rb, line 49
    def include_group? kind
       (@include == :all || @include.include?(kind)) &&
      !(@exclude == :all || @exclude.include?(kind))
    end

include_text_token?(text, kind) click to toggle source

    # File lib/coderay/encoders/token_kind_filter.rb, line 45
    def include_text_token? text, kind
      include_group? kind
    end

setup(options) click to toggle source

    # File lib/coderay/encoders/token_kind_filter.rb, line 35
    def setup options
      super

      @group_excluded = false
      @exclude = options[:exclude]
      @exclude = Array(@exclude) unless @exclude == :all
      @include = options[:include]
      @include = Array(@include) unless @include == :all
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.