Class: CodeRay::Encoders::Statistic

Inherits:
Encoder
  • Object
show all
Defined in:
lib/coderay/encoders/statistic.rb

Overview

Makes a statistic for the given tokens.

Alias: stats

Defined Under Namespace

Classes: TypeStats

Constant Summary

Constants inherited from Encoder

Encoder::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Encoder

#options, #scanner

Attributes included from Plugin

#plugin_id

Instance Method Summary collapse

Methods inherited from Encoder

#<<, const_missing, #encode, #encode_tokens, file_extension, #file_extension, #initialize, #token

Methods included from Plugin

#aliases, #plugin_host, #register_for, #title

Constructor Details

This class inherits a constructor from CodeRay::Encoders::Encoder

Instance Attribute Details

#real_token_countObject (readonly)

:nodoc:



11
12
13
# File 'lib/coderay/encoders/statistic.rb', line 11

def real_token_count
  @real_token_count
end

#type_statsObject (readonly)

:nodoc:



11
12
13
# File 'lib/coderay/encoders/statistic.rb', line 11

def type_stats
  @type_stats
end

Instance Method Details

#begin_group(kind) ⇒ Object



70
71
72
# File 'lib/coderay/encoders/statistic.rb', line 70

def begin_group kind
  block_token ':begin_group', kind
end

#begin_line(kind) ⇒ Object



78
79
80
# File 'lib/coderay/encoders/statistic.rb', line 78

def begin_line kind
  block_token ':begin_line', kind
end

#block_token(action, kind) ⇒ Object



86
87
88
89
90
# 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) ⇒ Object



74
75
76
# File 'lib/coderay/encoders/statistic.rb', line 74

def end_group kind
  block_token ':end_group', kind
end

#end_line(kind) ⇒ Object



82
83
84
# File 'lib/coderay/encoders/statistic.rb', line 82

def end_line kind
  block_token ':end_line', kind
end

#text_token(text, kind) ⇒ Object



62
63
64
65
66
67
68
# 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