Class: DebtCeiling::Accounting
- Inherits:
-
Object
- Object
- DebtCeiling::Accounting
- 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
-
#debts ⇒ Object
readonly
Returns the value of attribute debts.
-
#max_debt ⇒ Object
readonly
Returns the value of attribute max_debt.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#total_debt ⇒ Object
readonly
Returns the value of attribute total_debt.
Instance Method Summary collapse
- #calc_debt_for_modules(analysed_modules) ⇒ Object
- #construct_rubycritic_modules(path) ⇒ Object
- #get_max_debt ⇒ Object
- #get_total_debt ⇒ Object
-
#initialize(path) ⇒ Accounting
constructor
A new instance of Accounting.
- #method_count ⇒ Object
- #print_results ⇒ Object
- #smell_count ⇒ Object
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
#debts ⇒ Object (readonly)
Returns the value of attribute debts.
6 7 8 |
# File 'lib/debt_ceiling/accounting.rb', line 6 def debts @debts end |
#max_debt ⇒ Object (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 |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/debt_ceiling/accounting.rb', line 6 def path @path end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/debt_ceiling/accounting.rb', line 6 def result @result end |
#total_debt ⇒ Object (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_debt ⇒ Object
33 34 35 |
# File 'lib/debt_ceiling/accounting.rb', line 33 def get_max_debt debts.max_by(&:to_i) end |
#get_total_debt ⇒ Object
37 38 39 |
# File 'lib/debt_ceiling/accounting.rb', line 37 def get_total_debt debts.map(&:to_i).reduce(:+) end |
#method_count ⇒ Object
41 42 43 |
# File 'lib/debt_ceiling/accounting.rb', line 41 def method_count max_module.methods_count end |
#print_results ⇒ Object
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_count ⇒ Object
45 46 47 |
# File 'lib/debt_ceiling/accounting.rb', line 45 def smell_count max_module.smells.count end |