Commit e134eeeb2483371a7afc9f7cb78e3a251ddfbdbc
Committed by
Paulo Meireles
1 parent
3332d2e7
Exists in
master
and in
23 other branches
[Mezuro] refactoring metric result [not working]
Showing
5 changed files
with
50 additions
and
24 deletions
Show diff stats
| @@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
| 1 | +class Kalibro::MetricResult < Kalibro::Model | ||
| 2 | + | ||
| 3 | + attr_accessor :metric, :value, :range, :descendent_result, :weight | ||
| 4 | + | ||
| 5 | + def metric=(value) | ||
| 6 | + if value.kind_of?(Hash) | ||
| 7 | + compound?(value) ? @metric = to_object(value, Kalibro::CompoundMetric) : @metric = to_object(value, Kalibro::NativeMetric) | ||
| 8 | + else | ||
| 9 | + @metric = value | ||
| 10 | + end | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + def compound?(metric) | ||
| 14 | + metric.has_key?(:script) | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + def value=(value) | ||
| 18 | + @value = value.to_f | ||
| 19 | + end | ||
| 20 | + | ||
| 21 | + def range=(value) | ||
| 22 | + @range = to_object(value, Kalibro::Range) | ||
| 23 | + end | ||
| 24 | + | ||
| 25 | + def descendent_result=(value) | ||
| 26 | + array = value.kind_of?(Array) ? value : [value] | ||
| 27 | + @descendent_result = array.collect {|element| element.to_f} | ||
| 28 | + end | ||
| 29 | + | ||
| 30 | + def descendent_results | ||
| 31 | + @descendent_result | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | + def descendent_results=(descendent_results) | ||
| 35 | + @descendent_result = descendent_results | ||
| 36 | + end | ||
| 37 | + | ||
| 38 | +end |
plugins/mezuro/lib/kalibro/module_result.rb
| @@ -25,9 +25,8 @@ class Kalibro::ModuleResult < Kalibro::Model | @@ -25,9 +25,8 @@ class Kalibro::ModuleResult < Kalibro::Model | ||
| 25 | to_objects_array(response) | 25 | to_objects_array(response) |
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | - #FIXME change Kalibro::Entities::Module | ||
| 29 | def module=(value) | 28 | def module=(value) |
| 30 | - @module = value.kind_of?(Hash) ? Kalibro::Entities::Module.from_hash(value) : value | 29 | + @module = to_object(value, Kalibro::Module) |
| 31 | end | 30 | end |
| 32 | 31 | ||
| 33 | def date=(value) | 32 | def date=(value) |
| @@ -38,10 +37,8 @@ class Kalibro::ModuleResult < Kalibro::Model | @@ -38,10 +37,8 @@ class Kalibro::ModuleResult < Kalibro::Model | ||
| 38 | @grade = value.to_f | 37 | @grade = value.to_f |
| 39 | end | 38 | end |
| 40 | 39 | ||
| 41 | - #FIXME change Kalibro::Entities::MetricResult | ||
| 42 | def metric_result=(value) | 40 | def metric_result=(value) |
| 43 | - array = value.kind_of?(Array) ? value : [value] | ||
| 44 | - @metric_result = array.each.collect { |element| element.kind_of?(Hash) ? Kalibro::Entities::MetricResult.from_hash(element) : element } | 41 | + @metric_result = to_objects_array(value, Kalibro::MetricResult) |
| 45 | end | 42 | end |
| 46 | 43 | ||
| 47 | private | 44 | private |
plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures.rb
| @@ -4,13 +4,13 @@ class CompoundMetricWithErrorFixtures | @@ -4,13 +4,13 @@ class CompoundMetricWithErrorFixtures | ||
| 4 | 4 | ||
| 5 | def self.create | 5 | def self.create |
| 6 | fixture = Kalibro::Entities::CompoundMetricWithError.new | 6 | fixture = Kalibro::Entities::CompoundMetricWithError.new |
| 7 | - fixture.metric = CompoundMetricFixtures.sc | 7 | + fixture.metric = CompoundMetricFixtures.compound_metric |
| 8 | fixture.error = ErrorFixtures.create | 8 | fixture.error = ErrorFixtures.create |
| 9 | fixture | 9 | fixture |
| 10 | end | 10 | end |
| 11 | 11 | ||
| 12 | def self.create_hash | 12 | def self.create_hash |
| 13 | - {:metric => CompoundMetricFixtures.sc_hash, :error => ErrorFixtures.create_hash, | 13 | + {:metric => CompoundMetricFixtures.compound_metric_hash, :error => ErrorFixtures.create_hash, |
| 14 | :attributes! => {:metric => { | 14 | :attributes! => {:metric => { |
| 15 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | 15 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', |
| 16 | 'xsi:type' => 'kalibro:compoundMetricXml' }}} | 16 | 'xsi:type' => 'kalibro:compoundMetricXml' }}} |
plugins/mezuro/test/fixtures/metric_result_fixtures.rb
| @@ -4,24 +4,15 @@ require File.dirname(__FILE__) + '/range_fixtures' | @@ -4,24 +4,15 @@ require File.dirname(__FILE__) + '/range_fixtures' | ||
| 4 | 4 | ||
| 5 | class MetricResultFixtures | 5 | class MetricResultFixtures |
| 6 | 6 | ||
| 7 | - def self.amloc_result | ||
| 8 | - result = Kalibro::Entities::MetricResult.new | ||
| 9 | - result.metric = NativeMetricFixtures.amloc | ||
| 10 | - result.value = 0.0 | ||
| 11 | - result.descendent_results = [40.0, 42.0] | ||
| 12 | - result.range = RangeFixtures.range_excellent | ||
| 13 | - result | 7 | + def self.native_metric |
| 8 | + Kalibro::MetricResult.new( native_metric_hash ) | ||
| 14 | end | 9 | end |
| 15 | 10 | ||
| 16 | - def self.sc_result | ||
| 17 | - result = Kalibro::Entities::MetricResult.new | ||
| 18 | - result.metric = CompoundMetricFixtures.compound_metric | ||
| 19 | - result.value = 1.0 | ||
| 20 | - result.descendent_results = [2.0, 42.0] | ||
| 21 | - result | 11 | + def self.compound_metric |
| 12 | + Kalibro::MetricResult.new( compound_metric_hash ) | ||
| 22 | end | 13 | end |
| 23 | 14 | ||
| 24 | - def self.amloc_result_hash | 15 | + def self.native_metric_hash |
| 25 | {:metric => NativeMetricFixtures.amloc_hash, :value => 0.0, :descendent_result => [40.0, 42.0], | 16 | {:metric => NativeMetricFixtures.amloc_hash, :value => 0.0, :descendent_result => [40.0, 42.0], |
| 26 | :range => RangeFixtures.range_excellent_hash, | 17 | :range => RangeFixtures.range_excellent_hash, |
| 27 | :attributes! => {:metric => { | 18 | :attributes! => {:metric => { |
| @@ -29,7 +20,7 @@ class MetricResultFixtures | @@ -29,7 +20,7 @@ class MetricResultFixtures | ||
| 29 | 'xsi:type' => 'kalibro:nativeMetricXml' }}} | 20 | 'xsi:type' => 'kalibro:nativeMetricXml' }}} |
| 30 | end | 21 | end |
| 31 | 22 | ||
| 32 | - def self.sc_result_hash | 23 | + def self.compound_metric_hash |
| 33 | {:metric => CompoundMetricFixtures.compound_metric_hash, :value => 1.0, :descendent_result => [2.0, 42.0], | 24 | {:metric => CompoundMetricFixtures.compound_metric_hash, :value => 1.0, :descendent_result => [2.0, 42.0], |
| 34 | :attributes! => {:metric => { | 25 | :attributes! => {:metric => { |
| 35 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | 26 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', |
plugins/mezuro/test/fixtures/module_result_fixtures.rb
| @@ -14,8 +14,8 @@ class ModuleResultFixtures | @@ -14,8 +14,8 @@ class ModuleResultFixtures | ||
| 14 | :date => '2011-10-20T18:26:43.151+00:00', | 14 | :date => '2011-10-20T18:26:43.151+00:00', |
| 15 | :grade => 10.0, | 15 | :grade => 10.0, |
| 16 | :metric_result => [ | 16 | :metric_result => [ |
| 17 | - MetricResultFixtures.amloc_result_hash, | ||
| 18 | - MetricResultFixtures.sc_result_hash], | 17 | + MetricResultFixtures.native_metric_hash, |
| 18 | + MetricResultFixtures.compound_metric_hash], | ||
| 19 | :compound_metric_with_error => [CompoundMetricWithErrorFixtures.create_hash] | 19 | :compound_metric_with_error => [CompoundMetricWithErrorFixtures.create_hash] |
| 20 | } | 20 | } |
| 21 | end | 21 | end |