| Class | CodeRay::Encoders::Statistic |
| In: |
lib/coderay/encoders/statistic.rb
|
| Parent: | Encoder |
Makes a statistic for the given tokens.
| TypeStats | = | Struct.new :count, :size | ||
| STATS | = | <<-STATS Code Statistics Tokens %8d Non-Whitespace %8d Bytes Total %8d Token Types (%d): type count ratio size (average) ------------------------------------------------------------- %s STATS | ||
| TOKEN_TYPES_ROW | = | <<-TKR %-20s %8d %6.2f %% %5.1f TKR | space 12007 33.81 % 1.7 |
| real_token_count | [R] | |
| type_stats | [R] |
TODO Hierarchy handling
# File lib/coderay/encoders/statistic.rb, line 35
35: def block_token action, kind
36: @type_stats['TOTAL'].count += 1
37: @type_stats['open/close'].count += 1
38: end
# File lib/coderay/encoders/statistic.rb, line 60
60: def finish options
61: all = @type_stats['TOTAL']
62: all_count, all_size = all.count, all.size
63: @type_stats.each do |type, stat|
64: stat.size /= stat.count.to_f
65: end
66: types_stats = @type_stats.sort_by { |k, v| [-v.count, k.to_s] }.map do |k, v|
67: TOKEN_TYPES_ROW % [k, v.count, 100.0 * v.count / all_count, v.size]
68: end.join
69: STATS % [
70: all_count, @real_token_count, all_size,
71: @type_stats.delete_if { |k, v| k.is_a? String }.size,
72: types_stats
73: ]
74: end
# File lib/coderay/encoders/statistic.rb, line 21
21: def generate tokens, options
22: @tokens = tokens
23: super
24: end
# File lib/coderay/encoders/statistic.rb, line 16
16: def setup options
17: @type_stats = Hash.new { |h, k| h[k] = TypeStats.new 0, 0 }
18: @real_token_count = 0
19: end