Module: ChurnVsComplexity::Complexity::PythonCalculator
- Defined in:
- lib/churn_vs_complexity/complexity/python_calculator.rb
Class Attribute Summary collapse
-
.command_runner ⇒ Object
writeonly
Sets the attribute command_runner.
Class Method Summary collapse
- .calculate(files:) ⇒ Object
- .check_dependencies! ⇒ Object
- .folder_based? ⇒ Boolean
- .parse_radon_output(json_output, files:) ⇒ Object
Class Attribute Details
.command_runner=(value) ⇒ Object
Sets the attribute command_runner
10 11 12 |
# File 'lib/churn_vs_complexity/complexity/python_calculator.rb', line 10 def command_runner=(value) @command_runner = value end |
Class Method Details
.calculate(files:) ⇒ Object
14 15 16 17 |
# File 'lib/churn_vs_complexity/complexity/python_calculator.rb', line 14 def calculate(files:) json_output = run_radon(files) parse_radon_output(json_output, files:) end |
.check_dependencies! ⇒ Object
28 29 30 31 32 |
# File 'lib/churn_vs_complexity/complexity/python_calculator.rb', line 28 def check_dependencies! command_runner.call('radon --version 2>&1') rescue Errno::ENOENT raise Error, 'Needs radon installed (pip install radon)' end |
.folder_based? ⇒ Boolean
12 |
# File 'lib/churn_vs_complexity/complexity/python_calculator.rb', line 12 def folder_based? = false |
.parse_radon_output(json_output, files:) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/churn_vs_complexity/complexity/python_calculator.rb', line 19 def parse_radon_output(json_output, files:) data = JSON.parse(json_output) files.to_h do |file| blocks = data[file] || [] total = blocks.sum { |b| b['complexity'] } [file, total] end end |