class CodeRay::Encoders::Statistic

Alias: stats
Makes a statistic for the given tokens.

def begin_group kind

TODO Hierarchy handling
def begin_group kind
  block_token ':begin_group', kind
end

def begin_line kind

def begin_line kind
  block_token ':begin_line', kind
end

def block_token action, kind

def block_token action, kind
  @type_stats['TOTAL'].count += 1
  @type_stats[action].count += 1
  @type_stats[kind].count += 1
end

def end_group kind

def end_group kind
  block_token ':end_group', kind
end

def end_line kind

def end_line kind
  block_token ':end_line', kind
end

def finish options

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

def setup options

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

def text_token text, kind

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