Class: DebtCeiling::Accounting

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/debt_ceiling/accounting.rb

Constant Summary collapse

DebtCeilingExceeded =
Class.new(StandardError)
TargetDeadlineMissed =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Accounting

Returns a new instance of Accounting.



10
11
12
13
# File 'lib/debt_ceiling/accounting.rb', line 10

def initialize(path)
  @path = path
  calc_debt_for_modules(construct_rubycritic_modules(path))
end

Instance Attribute Details

#debtsObject (readonly)

Returns the value of attribute debts.



6
7
8
# File 'lib/debt_ceiling/accounting.rb', line 6

def debts
  @debts
end

#max_debtObject (readonly)

Returns the value of attribute max_debt.



6
7
8
# File 'lib/debt_ceiling/accounting.rb', line 6

def max_debt
  @max_debt
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/debt_ceiling/accounting.rb', line 6

def path
  @path
end

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/debt_ceiling/accounting.rb', line 6

def result
  @result
end

#total_debtObject (readonly)

Returns the value of attribute total_debt.



6
7
8
# File 'lib/debt_ceiling/accounting.rb', line 6

def total_debt
  @total_debt
end

Instance Method Details

#calc_debt_for_modules(analysed_modules) ⇒ Object



15
16
17
18
19
# File 'lib/debt_ceiling/accounting.rb', line 15

def calc_debt_for_modules(analysed_modules)
  @debts      = analysed_modules.map {|mod| Debt.new(FileAttributes.new(mod)) }
  @total_debt = get_total_debt
  @max_debt   = get_max_debt
end

#construct_rubycritic_modules(path) ⇒ Object



49
50
51
# File 'lib/debt_ceiling/accounting.rb', line 49

def construct_rubycritic_modules(path)
  Rubycritic.create(mode: :ci, format: :json, paths: Array(path)).critique
end

#get_max_debtObject



33
34
35
# File 'lib/debt_ceiling/accounting.rb', line 33

def get_max_debt
  debts.max_by(&:to_i)
end

#get_total_debtObject



37
38
39
# File 'lib/debt_ceiling/accounting.rb', line 37

def get_total_debt
  debts.map(&:to_i).reduce(:+)
end

#method_countObject



41
42
43
# File 'lib/debt_ceiling/accounting.rb', line 41

def method_count
  max_module.methods_count
end


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/debt_ceiling/accounting.rb', line 21

def print_results
  puts <<-RESULTS
    Current total tech debt: #{total_debt}
    Largest source of debt is: #{max_debt.name} at #{max_debt.to_i}
    The rubycritic grade for that debt is: #{max_debt.letter_grade}
    The flog complexity for that debt is: #{max_module.complexity}
    Flay suspects #{max_module.duplication.to_i} areas of code duplication
    There are #{method_count} methods and #{smell_count} smell(s) from reek.
    The file is #{max_debt.linecount} lines long.
  RESULTS
end

#smell_countObject



45
46
47
# File 'lib/debt_ceiling/accounting.rb', line 45

def smell_count
  max_module.smells.count
end