Class: CodeRay::TokensProxy

### Home Classes Methods

### In Files

- lib/coderay/tokens_proxy.rb

### Parent

Object

### Methods

- ::new
- #each
- #encode
- #method_missing
- #scanner
- #tokens

### 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::TokensProxy

The result of a scan operation is a TokensProxy, but should act like Tokens.

This proxy makes it possible to use the classic CodeRay.scan.encode API while still providing the benefits of direct streaming.

### Attributes

block[RW]
input[RW]
lang[RW]
options[RW]

### Public Class Methods

new(input, lang, options = {}) click to toggle source

Create a new TokensProxy with the arguments of CodeRay.scan.

    # File lib/coderay/tokens_proxy.rb, line 12
    def initialize input, lang, options = {}, block = nil
      @input   = input
      @lang    = lang
      @options = options
      @block   = block
    end

### Public Instance Methods

each(*args, &blk) click to toggle source

Overwrite Struct#each.

    # File lib/coderay/tokens_proxy.rb, line 48
    def each *args, &blk
      tokens.each(*args, &blk)
      self
    end

encode(encoder, options = {}) click to toggle source

Call CodeRay.encode if `encoder` is a Symbol; otherwise, convert the receiver to tokens and call encoder.encode_tokens.

    # File lib/coderay/tokens_proxy.rb, line 21
    def encode encoder, options = {}
      if encoder.respond_to? :to_sym
        CodeRay.encode(input, lang, encoder, options)
      else
        encoder.encode_tokens tokens, options
      end
    end

method_missing(method, *args, &blk) click to toggle source

Tries to call encode; delegates to tokens otherwise.

    # File lib/coderay/tokens_proxy.rb, line 31
    def method_missing method, *args, &blk
      encode method.to_sym, *args
    rescue PluginHost::PluginNotFound
      tokens.send(method, *args, &blk)
    end

scanner() click to toggle source

A (cached) scanner instance to use for the scan task.

    # File lib/coderay/tokens_proxy.rb, line 43
    def scanner
      @scanner ||= CodeRay.scanner(lang, options, &block)
    end

tokens() click to toggle source

The (cached) result of the tokenized input; a Tokens instance.

    # File lib/coderay/tokens_proxy.rb, line 38
    def tokens
      @tokens ||= scanner.tokenize(input)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.