Class: CodeRay::Encoders::LinesOfCode
- Inherits:
-
Encoder
- Object
- Encoder
- CodeRay::Encoders::LinesOfCode
- Defined in:
- vendor/plugins/coderay-0.9.2/lib/coderay/encoders/lines_of_code.rb
Overview
Counts the LoC (Lines of Code). Returns an Integer >= 0.
Alias: :loc
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, which defaults to [:comment, :doctype].
Constant Summary
- NON_EMPTY_LINE =
/^\s*\S.*$/
Constants inherited from Encoder
Instance Method Summary
Methods inherited from Encoder
const_missing, #encode, #encode_stream, #encode_tokens, #file_extension, #initialize, streamable?, #to_proc
Methods included from CodeRay::Plugin
#helper, #included, #plugin_host, #plugin_id, #register_for, #title
Constructor Details
This class inherits a constructor from CodeRay::Encoders::Encoder
Instance Method Details
- (Object) compile(tokens, options)
24 25 26 27 28 29 30 31 32 33 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoders/lines_of_code.rb', line 24 def compile tokens, if scanner = tokens.scanner kinds_not_loc = scanner.class::KINDS_NOT_LOC else warn ArgumentError, 'Tokens have no scanner.' if $VERBOSE kinds_not_loc = CodeRay::Scanners::Scanner::KINDS_NOT_LOC end code = tokens.token_class_filter :exclude => kinds_not_loc @loc = code.text.scan(NON_EMPTY_LINE).size end |
- (Object) finish(options)
35 36 37 |
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoders/lines_of_code.rb', line 35 def finish @loc end |