lib/metric_fu/metrics/cane/cane.rb in metric_fu-4.0.0 vs lib/metric_fu/metrics/cane/cane.rb in metric_fu-4.1.0

- old
+ new

@@ -3,11 +3,11 @@ module MetricFu class Cane < Generator attr_reader :violations, :total_violations def emit - command = %Q{mf-cane#{abc_max_param}#{style_measure_param}#{no_doc_param}} + command = %Q{mf-cane#{abc_max_param}#{style_measure_param}#{no_doc_param}#{no_readme_param}} mf_debug = "** #{command}" @output = `#{command}` end def analyze @@ -30,25 +30,32 @@ def no_doc_param MetricFu.cane[:no_doc] == 'y' ? " --no-doc" : "" end + def no_readme_param + MetricFu.cane[:no_readme] == 'y' ? " --no-readme" : "" + end + def violations_by_category violations_output = @output.scan(/(.*?)\n\n(.*?)\n\n/m) violations_output.each_with_object({}) do |(category_desc, violation_list), violations| - category = category_from(category_desc) - violations[category] = violations_for(category, violation_list) + category = category_from(category_desc) || :others + violations[category] ||= [] + violations[category] += violations_for(category, violation_list) end end def category_from(description) category_descriptions = { :abc_complexity => /ABC complexity/, :line_style => /style requirements/, - :comment => /comment/ + :comment => /comment/, + :documentation => /documentation/ } - category_descriptions.find {|k,v| description =~ v}[0] + category, desc_matcher = category_descriptions.find {|k,v| description =~ v} + category end def violations_for(category, violation_list) violation_type_for(category).parse(violation_list) end @@ -59,9 +66,13 @@ CaneViolations::AbcComplexity when :line_style CaneViolations::LineStyle when :comment CaneViolations::Comment + when :documentation + CaneViolations::Documentation + else + CaneViolations::Others end end def extract_total_violations total = @output.match(/Total Violations: (\d+)/)[1]