diff options
author | murphy <murphy@rubychan.de> | 2009-10-18 17:59:05 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2009-10-18 17:59:05 +0000 |
commit | a80108a38c4e16119c5263073d7d54fb6f3fadf7 (patch) | |
tree | c0f05c5126b46866d91623e4b961639d07bbc852 | |
parent | 6a93658b67deb2e12088264dd2da60a37834b0de (diff) | |
download | coderay-a80108a38c4e16119c5263073d7d54fb6f3fadf7.tar.gz |
LinesOfCode: Language dependent via KINDS_NOT_LOC, documentation.
-rw-r--r-- | lib/coderay/encoders/lines_of_code.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/coderay/encoders/lines_of_code.rb b/lib/coderay/encoders/lines_of_code.rb index 8ffe9dc..32c0192 100644 --- a/lib/coderay/encoders/lines_of_code.rb +++ b/lib/coderay/encoders/lines_of_code.rb @@ -1,12 +1,27 @@ module CodeRay module Encoders + # Counts the LoC (Lines of Code). Returns an Integer >= 0. + # + # Everything that is not comment, markup, doctype/shebang, or an empty line, + # is considered to be code. + # + # For example, + # * HTML files not containing JavaScript have 0 LoC + # * in a Java class without comments, LoC is the number of non-empty lines + # + # A Scanner class should define the token kinds that are not code in the + # KINDS_NOT_LOC constant. class LinesOfCode < Encoder register_for :lines_of_code + NON_EMPTY_LINE = /^\s*\S.*$/ + def compile tokens, options - @loc = tokens.token_class_filter(:exclude => [:comment, :doctype]).text.scan(/^\s*\S.*$/).size + kinds_not_loc = tokens.scanner.class::KINDS_NOT_LOC + code = tokens.token_class_filter :exclude => kinds_not_loc + @loc = code.text.scan(NON_EMPTY_LINE).size end def finish options |