Sha256: 062e7d6625d5ff92042657d7597a5fb7ef67ab5422f05eba1f11a4645e99dd03

Contents?: true

Size: 744 Bytes

Versions: 34

Compression:

Stored size: 744 Bytes

Contents

# frozen_string_literal: true

module DeepCover
  module Tools::NumberLines
    def number_lines(lines, lineno: 1, bad_linenos: [])
      max_lineno = lineno + lines.size - 1
      nb_lineno_digits = max_lineno.to_s.size
      lines.map.with_index do |line, i|
        cur_lineno = lineno + i
        cur_lineno_s = cur_lineno.to_s.rjust(nb_lineno_digits)
        if bad_linenos.include?(cur_lineno)
          cur_lineno_s = "*#{cur_lineno_s}" unless bad_linenos.empty?
          prefix = Term::ANSIColor.red("#{cur_lineno_s} | ")
        else
          cur_lineno_s = " #{cur_lineno_s}" unless bad_linenos.empty?
          prefix = Term::ANSIColor.white("#{cur_lineno_s} | ")
        end
        "#{prefix}#{line}"
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
deep-cover-core-1.1.0 lib/deep_cover/tools/number_lines.rb
deep-cover-core-1.0.0 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.8.1 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.8.0 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.10 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.9 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.8 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.7 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.6 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.5 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.4 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.3 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.2 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.1 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.7.0 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.6.4 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.6.3 lib/deep_cover/tools/number_lines.rb
deep-cover-core-0.6.3.pre lib/deep_cover/tools/number_lines.rb
deep-cover-0.6.2 lib/deep_cover/tools/number_lines.rb
deep-cover-0.6.1 lib/deep_cover/tools/number_lines.rb