Sha256: 31cb18291e03c118c59cfafd9d2f4f1db4d8f0bb8cf1f42d8a8f7cb4821973f0

Contents?: true

Size: 773 Bytes

Versions: 3

Compression:

Stored size: 773 Bytes

Contents

# frozen_string_literal: true

require "json"

module Attractor
  # holds a churn/complexity value
  class Value
    attr_reader :file_path, :churn, :complexity, :details, :history

    def initialize(file_path: "", churn: 1, complexity: 0, details: [], history: [])
      @file_path = file_path
      @churn = churn
      @complexity = complexity
      @details = details
      @history = history
    end

    def current_commit
      history&.first&.first
    end

    def score
      @complexity * @churn
    end

    def to_s
      format("%-64s%8.1f%8i", @file_path, @complexity, @churn)
    end

    def to_h
      {file_path: file_path, x: churn, y: complexity, details: details, history: history}
    end

    def to_json(_opt)
      to_h.to_json
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
attractor-2.6.0 lib/attractor/value.rb
attractor-2.5.0 lib/attractor/value.rb
attractor-2.4.0 lib/attractor/value.rb