Class CodeRay::Encoders::Statistic
In: lib/coderay/encoders/statistic.rb
Parent: Encoder

Makes a statistic for the given tokens.

Alias: stats

Methods

Public Instance methods

TODO Hierarchy handling

[Source]

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

[Source]

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

[Source]

    # File lib/coderay/encoders/statistic.rb, line 89
89:     def block_token action, kind
90:       @type_stats['TOTAL'].count += 1
91:       @type_stats[action].count += 1
92:       @type_stats[kind].count += 1
93:     end

[Source]

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

[Source]

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

[Source]

    # File lib/coderay/encoders/statistic.rb, line 64
64:     def text_token text, kind
65:       @real_token_count += 1 unless kind == :space
66:       @type_stats[kind].count += 1
67:       @type_stats[kind].size += text.size
68:       @type_stats['TOTAL'].size += text.size
69:       @type_stats['TOTAL'].count += 1
70:     end

Protected Instance methods

[Source]

    # File lib/coderay/encoders/statistic.rb, line 44
44:     def finish options
45:       all = @type_stats['TOTAL']
46:       all_count, all_size = all.count, all.size
47:       @type_stats.each do |type, stat|
48:         stat.size /= stat.count.to_f
49:       end
50:       types_stats = @type_stats.sort_by { |k, v| [-v.count, k.to_s] }.map do |k, v|
51:         TOKEN_TYPES_ROW % [k, v.count, 100.0 * v.count / all_count, v.size]
52:       end.join
53:       @out << STATS % [
54:         all_count, @real_token_count, all_size,
55:         @type_stats.delete_if { |k, v| k.is_a? String }.size,
56:         types_stats
57:       ]
58:       
59:       super
60:     end

[Source]

    # File lib/coderay/encoders/statistic.rb, line 17
17:     def setup options
18:       super
19:       
20:       @type_stats = Hash.new { |h, k| h[k] = TypeStats.new 0, 0 }
21:       @real_token_count = 0
22:     end

[Validate]