Class: FlogBuilder
Overview
Construction de la tache flog (complexite du code ruby)
Code inspired by the metric_fu gem by Jake Scruggs
author: Vincent Dubois
date: 06 fevrier 2009
Defined Under Namespace
Classes: Operator, Page, ScannedMethod
Constant Summary collapse
- METHOD_LINE_REGEX =
/([A-Za-z]+#.*):\s\((\d+\.\d+)\)/- OPERATOR_LINE_REGEX =
/\s+(\d+\.\d+):\s(.*)$/
Instance Method Summary collapse
-
#build(project_name, auto_install, proxy_option) ⇒ Object
Implementation de la construction de la tache.
- #parse(text) ⇒ Object
-
#quality_indicator_name ⇒ Object
Nom de l’indicateur de qualité.
-
#quality_percentage ⇒ Object
Methode qui permet d’extraire le pourcentage de qualité extrait d’un builder.
- #save_html(content, file = 'index.html') ⇒ Object
Methods included from Utils
build_name, erb_run, flog_caracteristics, flog_score_to_css_style, percent_to_css_style, run_command, verify_gem_presence
Instance Method Details
#build(project_name, auto_install, proxy_option) ⇒ Object
Implementation de la construction de la tache
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/flog_builder.rb', line 90 def build(project_name, auto_install, proxy_option) # On verifie la presence de flog Utils.verify_gem_presence("flog", auto_install, proxy_option) # On lance la generation puts " Building flog report..." FileUtils.mkdir("#{Continuous4r::WORK_DIR}/flog") files = Array.new files << Dir.glob("app/**/*.rb") files << Dir.glob("lib/**/*.rb") files << Dir.glob("test/**/*.rb") files.flatten! files.each do |filename| puts "Processing #{filename}..." output_dir = "#{Continuous4r::WORK_DIR}/flog/#{filename.split("/")[0..-2].join("/")}" FileUtils.mkdir_p(output_dir, :verbose => false) unless File.directory?(output_dir) Utils.run_command("flog #{filename} > #{Continuous4r::WORK_DIR}/flog/#{filename.split('.')[0]}.txt") end pages = Array.new Dir.glob("#{Continuous4r::WORK_DIR}/flog/**/*.txt").each do |filename| page = parse(File.read(filename)) if page page.filename = filename pages << page end end pages.each do |page| save_html(page.to_html, page.path) end save_html(ERB.new(File.read(File.join(File.dirname(__FILE__), "site/flog.html.erb"))).result(binding)) end |
#parse(text) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/flog_builder.rb', line 65 def parse(text) score = text[/\w+ = (\d+\.\d+)/, 1] return nil unless score page = Page.new(score) text.each_line do |method_line| if match = method_line.match(METHOD_LINE_REGEX) page.scanned_methods << ScannedMethod.new(match[1], match[2]) end if match = method_line.match(OPERATOR_LINE_REGEX) return if page.scanned_methods.empty? page.scanned_methods.last.operators << Operator.new(match[1], match[2]) end end page end |
#quality_indicator_name ⇒ Object
Nom de l’indicateur de qualité
141 142 143 |
# File 'lib/flog_builder.rb', line 141 def quality_indicator_name "code complexity" end |
#quality_percentage ⇒ Object
Methode qui permet d’extraire le pourcentage de qualité extrait d’un builder
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/flog_builder.rb', line 122 def quality_percentage require 'hpricot' doc = Hpricot(File.read("#{Continuous4r::WORK_DIR}/flog/index.html")) doc.search('//h3') do |h3| if h3.inner_text.match(/^Project average score/) score = h3.inner_text.split(/Project average score : /)[1].to_f if score > 100.0 percent = 0 elsif score < 11.0 percent = 100 else percent = ((100.0 - score) * 100.0) / 89.0 end return percent end end end |
#save_html(content, file = 'index.html') ⇒ Object
83 84 85 86 87 |
# File 'lib/flog_builder.rb', line 83 def save_html(content, file='index.html') f = File.open("#{Continuous4r::WORK_DIR}/flog/#{file}", "w") f.write(content) f.close end |