Sha256: cc1e40645888070ba71ddf8fce045ab7436ba2cf18300747c492444a18a26f09

Contents?: true

Size: 1012 Bytes

Versions: 1

Compression:

Stored size: 1012 Bytes

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: 80}
      )
      table.align_column(3, :right)
      puts table
    end

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

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fukuzatsu-1.0.0 lib/fukuzatsu/formatters/text.rb