summaryrefslogtreecommitdiff
path: root/lib/coderay/encoders/lines_of_code.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2011-04-20 19:49:53 +0000
committermurphy <murphy@rubychan.de>2011-04-20 19:49:53 +0000
commitaa17b9942d6ca3d01e3f74513e0903a195c23b22 (patch)
treeeeee0ac8f13199d726f9eeb8f4ad7194773f0d36 /lib/coderay/encoders/lines_of_code.rb
parent763948b33279a418b17f09f110e8cab0035a0734 (diff)
downloadcoderay-aa17b9942d6ca3d01e3f74513e0903a195c23b22.tar.gz
Encoder refactoring to fix LOC and Statistic encoders
Diffstat (limited to 'lib/coderay/encoders/lines_of_code.rb')
-rw-r--r--lib/coderay/encoders/lines_of_code.rb15
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/coderay/encoders/lines_of_code.rb b/lib/coderay/encoders/lines_of_code.rb
index 4215d23..c49cade 100644
--- a/lib/coderay/encoders/lines_of_code.rb
+++ b/lib/coderay/encoders/lines_of_code.rb
@@ -14,7 +14,7 @@ module Encoders
#
# A Scanner class should define the token kinds that are not code in the
# KINDS_NOT_LOC constant, which defaults to [:comment, :doctype].
- class LinesOfCode < Encoder
+ class LinesOfCode < TokenKindFilter
register_for :lines_of_code
@@ -23,22 +23,19 @@ module Encoders
protected
def setup options
- @out = 0
- end
-
- def compile tokens, options
- if scanner = tokens.scanner
+ if scanner
kinds_not_loc = scanner.class::KINDS_NOT_LOC
else
warn "Tokens have no associated scanner, counting all nonempty lines." if $VERBOSE
kinds_not_loc = CodeRay::Scanners::Scanner::KINDS_NOT_LOC
end
- code = tokens.token_kind_filter :exclude => kinds_not_loc
- @out = code.to_s.scan(NON_EMPTY_LINE).size
+
+ options[:exclude] = kinds_not_loc
+ super options
end
def finish options
- @out
+ @out.to_s.scan(NON_EMPTY_LINE).size
end
end