analizo_extractor.rb
895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class MezuroPlugin::AnalizoExtractor < Noosfero::Plugin::ActiveRecord
attr_reader :string_output, :hash_output
def initialize project
@project = project
end
def perform
run_analizo
create_hash
save_metrics
end
def run_analizo
project_path = "#{RAILS_ROOT}/tmp/#{@project.identifier}"
@string_output = `analizo metrics #{project_path}`
end
def create_hash
@hash_output = {}
first_line = true
@string_output.lines.each do |line|
if line =~ /---/
if first_line
first_line = false
else
break
end
end
if line =~ /(\S+): (~|(\d+)(\.\d+)?).*/
@hash_output[$1.to_sym] = $2
end
end
end
def save_metrics
@hash_output.each do | key, value |
MezuroPlugin::Metric.create(:name => key.to_s, :value => value.to_f, :metricable => @project)
end
end
end