Module: ChurnVsComplexity::Complexity::SwiftCalculator
- Defined in:
- lib/churn_vs_complexity/complexity/swift_calculator.rb
Constant Summary collapse
- LIZARD_LINE_PATTERN =
Lizard CSV format: NLOC,CCN,tokens,params,length,"loc","file","func","long_func",start,end
/^\d+,(\d+),\d+,\d+,\d+,"[^"]*","([^"]*)"/
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_lizard_output(csv_output, files:) ⇒ Object
Class Attribute Details
.command_runner=(value) ⇒ Object
Sets the attribute command_runner
9 10 11 |
# File 'lib/churn_vs_complexity/complexity/swift_calculator.rb', line 9 def command_runner=(value) @command_runner = value end |
Class Method Details
.calculate(files:) ⇒ Object
13 14 15 16 |
# File 'lib/churn_vs_complexity/complexity/swift_calculator.rb', line 13 def calculate(files:) csv_output = run_lizard(files) parse_lizard_output(csv_output, files:) end |
.check_dependencies! ⇒ Object
32 33 34 35 36 |
# File 'lib/churn_vs_complexity/complexity/swift_calculator.rb', line 32 def check_dependencies! command_runner.call('lizard --version 2>&1') rescue Errno::ENOENT raise Error, 'Needs lizard installed (pip install lizard)' end |
.folder_based? ⇒ Boolean
11 |
# File 'lib/churn_vs_complexity/complexity/swift_calculator.rb', line 11 def folder_based? = false |
.parse_lizard_output(csv_output, files:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/churn_vs_complexity/complexity/swift_calculator.rb', line 21 def parse_lizard_output(csv_output, files:) scores = Hash.new(0) csv_output.each_line do |line| match = line.match(LIZARD_LINE_PATTERN) next unless match scores[match[2]] += match[1].to_i end files.to_h { |file| [file, scores[file] || 0] } end |