Class: CodeRay::Encoders::Statistic

### Home Classes Methods

### In Files

- lib/coderay/encoders/statistic.rb

### Parent

CodeRay::Encoders::Encoder

### Methods

- #begin_group
- #begin_line
- #block_token
- #end_group
- #end_line
- #finish
- #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::Statistic

Makes a statistic for the given tokens.

Alias: `stats`

### Public Instance Methods

begin_group(kind) click to toggle source

    # File lib/coderay/encoders/statistic.rb, line 70
    def begin_group kind
      block_token ':begin_group', kind
    end

begin_line(kind) click to toggle source

    # File lib/coderay/encoders/statistic.rb, line 78
    def begin_line kind
      block_token ':begin_line', kind
    end

block_token(action, kind) click to toggle source

    # File lib/coderay/encoders/statistic.rb, line 86
    def block_token action, kind
      @type_stats['TOTAL'].count += 1
      @type_stats[action].count += 1
      @type_stats[kind].count += 1
    end

end_group(kind) click to toggle source

    # File lib/coderay/encoders/statistic.rb, line 74
    def end_group kind
      block_token ':end_group', kind
    end

end_line(kind) click to toggle source

    # File lib/coderay/encoders/statistic.rb, line 82
    def end_line kind
      block_token ':end_line', kind
    end

text_token(text, kind) click to toggle source

    # File lib/coderay/encoders/statistic.rb, line 62
    def text_token text, kind
      @real_token_count += 1 unless kind == :space
      @type_stats[kind].count += 1
      @type_stats[kind].size += text.size
      @type_stats['TOTAL'].size += text.size
      @type_stats['TOTAL'].count += 1
    end

### Protected Instance Methods

finish(options) click to toggle source

    # File lib/coderay/encoders/statistic.rb, line 42
    def finish options
      all = @type_stats['TOTAL']
      all_count, all_size = all.count, all.size
      @type_stats.each do |type, stat|
        stat.size /= stat.count.to_f
      end
      types_stats = @type_stats.sort_by { |k, v| [-v.count, k.to_s] }.map do |k, v|
        TOKEN_TYPES_ROW % [k, v.count, 100.0 * v.count / all_count, v.size]
      end.join
      @out << STATS % [
        all_count, @real_token_count, all_size,
        @type_stats.delete_if { |k, v| k.is_a? String }.size,
        types_stats
      ]

      super
    end

setup(options) click to toggle source

    # File lib/coderay/encoders/statistic.rb, line 17
    def setup options
      super

      @type_stats = Hash.new { |h, k| h[k] = TypeStats.new 0, 0 }
      @real_token_count = 0
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.