Class: CodeRay::Encoders::LinesOfCode

### Home Classes Methods

### In Files

- lib/coderay/encoders/lines_of_code.rb

### Parent

TokenKindFilter

### Methods

- #finish
- #setup

### Class/Module Index

Quicksearch

- CodeRay
- CodeRay::Duo
- CodeRay::Encoders
- CodeRay::Encoders::CommentFilter
- CodeRay::Encoders::Count
- CodeRay::Encoders::Debug
- CodeRay::Encoders::DebugLint
- CodeRay::Encoders::Div
- CodeRay::Encoders::Encoder
- CodeRay::Encoders::Filter
- CodeRay::Encoders::HTML
- CodeRay::Encoders::HTML::Output
- CodeRay::Encoders::JSON
- CodeRay::Encoders::LinesOfCode
- CodeRay::Encoders::Lint
- CodeRay::Encoders::Null
- CodeRay::Encoders::Page
- CodeRay::Encoders::Span
- CodeRay::Encoders::Statistic
- CodeRay::Encoders::Terminal
- CodeRay::Encoders::Text
- CodeRay::Encoders::TokenKindFilter
- CodeRay::Encoders::XML
- CodeRay::Encoders::YAML
- CodeRay::FileType
- CodeRay::ForRedCloth
- CodeRay::Plugin
- CodeRay::PluginHost
- CodeRay::Scanners
- CodeRay::Scanners::C
- CodeRay::Scanners::CPlusPlus
- CodeRay::Scanners::CSS
- CodeRay::Scanners::Clojure
- CodeRay::Scanners::Debug
- CodeRay::Scanners::Delphi
- CodeRay::Scanners::Diff
- CodeRay::Scanners::ERB
- CodeRay::Scanners::Go
- CodeRay::Scanners::Groovy
- CodeRay::Scanners::HAML
- CodeRay::Scanners::HTML
- CodeRay::Scanners::JSON
- CodeRay::Scanners::Java
- CodeRay::Scanners::JavaScript
- CodeRay::Scanners::Python
- CodeRay::Scanners::Raydebug
- CodeRay::Scanners::Ruby
- CodeRay::Scanners::SQL
- CodeRay::Scanners::Sass
- CodeRay::Scanners::Scanner
- CodeRay::Scanners::Taskpaper
- CodeRay::Scanners::Text
- CodeRay::Scanners::XML
- CodeRay::Scanners::YAML
- CodeRay::Styles
- CodeRay::Styles::Alpha
- CodeRay::Styles::Style
- CodeRay::Tokens
- CodeRay::TokensProxy
- CodeRay::WordList
- CodeRay::WordList::CaseIgnoring

No matching classes.

# CodeRay::Encoders::LinesOfCode

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

### Constants

NON_EMPTY_LINE

### Protected Instance Methods

finish(options) click to toggle source

    # File lib/coderay/encoders/lines_of_code.rb, line 38
    def finish options
      output @tokens.text.scan(NON_EMPTY_LINE).size
    end

setup(options) click to toggle source

    # File lib/coderay/encoders/lines_of_code.rb, line 25
    def setup options
      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

      options[:exclude] = kinds_not_loc

      super options
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.