Class: SimpleCov::SourceFile::Line

### Home Classes Methods

### In Files

- lib/simplecov/source_file.rb

### Parent

Object

### Methods

- ::new
- #covered?
- #missed?
- #never?
- #skipped!
- #skipped?
- #status

### Class/Module Index

Quicksearch

- SimpleCov
- SimpleCov::Adapters
- SimpleCov::ArrayMergeHelper
- SimpleCov::BlockFilter
- SimpleCov::CommandGuesser
- SimpleCov::Configuration
- SimpleCov::CoverageDataError
- SimpleCov::ExitCodes
- SimpleCov::FileList
- SimpleCov::Filter
- SimpleCov::Formatter
- SimpleCov::Formatter::MultiFormatter
- SimpleCov::Formatter::SimpleFormatter
- SimpleCov::HashMergeHelper
- SimpleCov::JSON
- SimpleCov::LastRun
- SimpleCov::Railtie
- SimpleCov::Result
- SimpleCov::ResultMerger
- SimpleCov::SourceFile
- SimpleCov::SourceFile::Line
- SimpleCov::StringFilter

No matching classes.

# SimpleCov::SourceFile::Line

Representation of a single line in a source file including this specific line's source code, line_number and code coverage, with the coverage being either nil (coverage not applicable, e.g. comment line), 0 (line not covered) or >1 (the amount of times the line was executed)

### Attributes

coverage[R]

The coverage data for this line: either nil (never), 0 (missed) or >=1 (times covered)

line[R]

The line number in the source file. Aliased as :line, :number

line_number[R]

The line number in the source file. Aliased as :line, :number

number[R]

The line number in the source file. Aliased as :line, :number

skipped[R]

Whether this line was skipped

source[R]

The source code for this line. Aliased as :source

src[R]

The source code for this line. Aliased as :source

### Public Class Methods

new(src, line_number, coverage) click to toggle source

    # File lib/simplecov/source_file.rb, line 27
    def initialize(src, line_number, coverage)
      raise ArgumentError, "Only String accepted for source" unless src.kind_of?(String)
      raise ArgumentError, "Only Fixnum accepted for line_number" unless line_number.kind_of?(Fixnum)
      raise ArgumentError, "Only Fixnum and nil accepted for coverage" unless coverage.kind_of?(Fixnum) or coverage.nil?
      @src, @line_number, @coverage = src, line_number, coverage
      @skipped = false
      @src.encode!('UTF-8', 'UTF-8', :invalid => :replace) if @src.respond_to?(:encode!)
    end

### Public Instance Methods

covered?() click to toggle source

Returns true if this is a line that has been covered

    # File lib/simplecov/source_file.rb, line 42
    def covered?
      not never? and not skipped? and coverage > 0
    end

missed?() click to toggle source

Returns true if this is a line that should have been covered, but was not

    # File lib/simplecov/source_file.rb, line 37
    def missed?
      not never? and not skipped? and coverage == 0
    end

never?() click to toggle source

Returns true if this line is not relevant for coverage

    # File lib/simplecov/source_file.rb, line 47
    def never?
      not skipped? and coverage.nil?
    end

skipped!() click to toggle source

Flags this line as skipped

    # File lib/simplecov/source_file.rb, line 52
    def skipped!
      @skipped = true
    end

skipped?() click to toggle source

Returns true if this line was skipped, false otherwise. Lines are skipped if they are wrapped with # :nocov: comment lines.

    # File lib/simplecov/source_file.rb, line 58
    def skipped?
            !!skipped
    end

status() click to toggle source

The status of this line - either covered, missed, skipped or never. Useful i.e. for direct use as a css class in report generation

    # File lib/simplecov/source_file.rb, line 64
    def status
      return 'skipped' if skipped?
      return 'never' if never?
      return 'missed' if missed?
      return 'covered' if covered?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.