Class CodeRay::Encoders::LinesOfCode
In: lib/coderay/encoders/lines_of_code.rb
Parent: Encoder

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].

Methods

compile   finish  

Constants

NON_EMPTY_LINE = /^\s*\S.*$/

Public Instance methods

[Source]

    # File lib/coderay/encoders/lines_of_code.rb, line 24
24:     def compile tokens, options
25:       if scanner = tokens.scanner
26:         kinds_not_loc = scanner.class::KINDS_NOT_LOC
27:       else
28:         warn ArgumentError, 'Tokens have no scanner.' if $VERBOSE
29:         kinds_not_loc = CodeRay::Scanners::Scanner::KINDS_NOT_LOC
30:       end
31:       code = tokens.token_class_filter :exclude => kinds_not_loc
32:       @loc = code.text.scan(NON_EMPTY_LINE).size
33:     end

[Source]

    # File lib/coderay/encoders/lines_of_code.rb, line 35
35:     def finish options
36:       @loc
37:     end

[Validate]