Sha256: 1f62346f402597ff9cc8adcf1f291bf3f472fc6ea26541aacf8a72aee27706f9

Contents?: true

Size: 1.1 KB

Versions: 6990

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,990 entries across 6,977 versions & 75 rubygems

Version Path
coderay-1.1.3.rc1 lib/coderay/encoders/lines_of_code.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
talon_one-2.0.0 vendor/bundle/ruby/2.7.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
chess_engine-0.0.2 vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
chess_engine-0.0.1 vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
xaiml-0.1.3 vendor/bundle/ruby/2.5.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
xaiml-0.1.2 vendor/bundle/ruby/2.5.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
xaiml-0.1.1 vendor/bundle/ruby/2.5.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
xaiml-0.1.0 vendor/bundle/ruby/2.5.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb