Sha256: 1f62346f402597ff9cc8adcf1f291bf3f472fc6ea26541aacf8a72aee27706f9

Contents?: true

Size: 1.1 KB

Versions: 6662

Compression:

Stored size: 1.1 KB

Contents

module CodeRay
module Encoders
  
  # 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].
  class LinesOfCode < TokenKindFilter
    
    register_for :lines_of_code
    
    NON_EMPTY_LINE = /^\s*\S.*$/
    
  protected
    
    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
    
    def finish options
      output @tokens.text.scan(NON_EMPTY_LINE).size
    end
    
  end
  
end
end

Version data entries

6,662 entries across 6,650 versions & 72 rubygems

Version Path
cybrid_api_organization_ruby-0.122.67 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_id_ruby-0.122.67 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_bank_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_organization_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_id_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_id_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_bank_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_organization_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_bank_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_id_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_organization_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_id_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_bank_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_organization_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_organization_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_bank_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_id_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_bank_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_organization_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb
cybrid_api_id_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb