Sha256: 8e5428996d4f0a303c9eb356bb9aba3276356df9a06f718c68ae2dec4ef900c2

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Formatters

  require 'terminal-table'
  require 'rainbow/ext/string'

  class Text

    include Formatters::Base

    def self.has_index?
      false
    end

    def self.writes_to_file_system?
      false
    end

    def color_for(row)
      return :green if row.complexity == 0
      return :yellow if row.complexity <= file.average_complexity
      return :red if row.complexity > file.average_complexity
      return :white
    end

    def header
      ["Class/Module", "Method", "Complexity"]
    end

    def export
      return if rows.empty?
      table = Terminal::Table.new(
        title: file.path_to_file.color(:white),
        headings: header,
        rows: rows,
        style: {width: 90}
      )
      table.align_column(3, :right)
      puts table
    end

    def rows
      file.methods.map do |method|
        color = color_for(method)
        [wrap("#{file.class_name}").color(color), wrap("#{method.name}".color(color)), "#{method.complexity}".color(color)]
      end
    end

    def wrap(string)
      return string if string.length < 25
      string[0..20] << "..."
    end

  end

end

Version data entries

4 entries across 3 versions & 2 rubygems

Version Path
analyst-0.13.1 lib/analyst/formatters/text.rb
analyst-0.13.1 lib/analyst/fukuzatsu/formatters/text.rb
fukuzatsu-1.0.6 lib/fukuzatsu/formatters/text.rb
fukuzatsu-1.0.5 lib/fukuzatsu/formatters/text.rb