Class: Attractor::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/attractor/value.rb

Overview

holds a churn/complexity value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path: "", churn: 1, complexity: 0, details: [], history: []) ⇒ Value

Returns a new instance of Value.



10
11
12
13
14
15
16
# File 'lib/attractor/value.rb', line 10

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

Instance Attribute Details

#churnObject (readonly)

Returns the value of attribute churn.



8
9
10
# File 'lib/attractor/value.rb', line 8

def churn
  @churn
end

#complexityObject (readonly)

Returns the value of attribute complexity.



8
9
10
# File 'lib/attractor/value.rb', line 8

def complexity
  @complexity
end

#detailsObject (readonly)

Returns the value of attribute details.



8
9
10
# File 'lib/attractor/value.rb', line 8

def details
  @details
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



8
9
10
# File 'lib/attractor/value.rb', line 8

def file_path
  @file_path
end

#historyObject (readonly)

Returns the value of attribute history.



8
9
10
# File 'lib/attractor/value.rb', line 8

def history
  @history
end

Instance Method Details

#current_commitObject



18
19
20
# File 'lib/attractor/value.rb', line 18

def current_commit
  history&.first&.first
end

#scoreObject



22
23
24
# File 'lib/attractor/value.rb', line 22

def score
  @complexity * @churn
end

#to_hObject



30
31
32
# File 'lib/attractor/value.rb', line 30

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

#to_json(_opt) ⇒ Object



34
35
36
# File 'lib/attractor/value.rb', line 34

def to_json(_opt)
  to_h.to_json
end

#to_sObject



26
27
28
# File 'lib/attractor/value.rb', line 26

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