Commit d773724af34fed7787fedd0c2f74f3906906abd5
Committed by
Paulo Meireles
1 parent
5e54605b
Exists in
staging
and in
42 other branches
[Mezuro] Refactored Range entity to Range Model.
Showing
6 changed files
with
47 additions
and
57 deletions
Show diff stats
plugins/mezuro/lib/kalibro/entities/range.rb
... | ... | @@ -1,19 +0,0 @@ |
1 | -class Kalibro::Entities::Range < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :beginning, :end, :label, :grade, :color, :comments | |
4 | - | |
5 | - def beginning=(value) | |
6 | - @beginning = value.to_f | |
7 | - @beginning = -1.0/0.0 if value == "-INF" | |
8 | - end | |
9 | - | |
10 | - def end=(value) | |
11 | - @end = value.to_f | |
12 | - @end = 1.0/0.0 if value == "INF" | |
13 | - end | |
14 | - | |
15 | - def grade=(value) | |
16 | - @grade = value.to_f | |
17 | - end | |
18 | - | |
19 | -end | |
20 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/model.rb
... | ... | @@ -29,6 +29,8 @@ class Kalibro::Model |
29 | 29 | return value if value.nil? |
30 | 30 | return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) |
31 | 31 | return value.to_hash if value.is_a?(Kalibro::Model) |
32 | + return 'INF' if value.is_a?(Float) and value.infinite? == 1 | |
33 | + return '-INF' if value.is_a?(Float) and value.infinite? == -1 | |
32 | 34 | value |
33 | 35 | end |
34 | 36 | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +class Kalibro::Range < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :beginning, :end, :label, :grade, :color, :comments | |
4 | + | |
5 | + def beginning=(value) | |
6 | + @beginning = value.to_f | |
7 | + @beginning = -1.0/0.0 if value == "-INF" | |
8 | + end | |
9 | + | |
10 | + def end=(value) | |
11 | + @end = value.to_f | |
12 | + @end = 1.0/0.0 if value == "INF" | |
13 | + end | |
14 | + | |
15 | + def grade=(value) | |
16 | + @grade = value.to_f | |
17 | + end | |
18 | + | |
19 | +end | ... | ... |
plugins/mezuro/test/fixtures/range_fixtures.rb
... | ... | @@ -2,31 +2,19 @@ class RangeFixtures |
2 | 2 | |
3 | 3 | Infinity = 1.0/0.0 |
4 | 4 | |
5 | - def self.amloc_excellent | |
6 | - range = Kalibro::Entities::Range.new | |
7 | - range.beginning = 0.0 | |
8 | - range.end = 7.0 | |
9 | - range.label = 'Excellent' | |
10 | - range.grade = 10.0 | |
11 | - range.color = 'ff00ff00' | |
12 | - range | |
5 | + def self.range_excellent | |
6 | + Kalibro::Range.new range_excellent_hash | |
13 | 7 | end |
14 | 8 | |
15 | - def self.amloc_bad | |
16 | - range = Kalibro::Entities::Range.new | |
17 | - range.beginning = 19.5 | |
18 | - range.end = Infinity | |
19 | - range.label = 'Bad' | |
20 | - range.grade = 0.0 | |
21 | - range.color = 'ffff0000' | |
22 | - range | |
9 | + def self.range_bad | |
10 | + Kalibro::Range.new range_bad_hash | |
23 | 11 | end |
24 | 12 | |
25 | - def self.amloc_excellent_hash | |
13 | + def self.range_excellent_hash | |
26 | 14 | {:beginning => 0.0, :end => 7.0, :label => 'Excellent', :grade => 10.0, :color => 'ff00ff00'} |
27 | 15 | end |
28 | 16 | |
29 | - def self.amloc_bad_hash | |
17 | + def self.range_bad_hash | |
30 | 18 | {:beginning => 19.5, :end => "INF", :label => 'Bad',:grade => 0.0, :color => 'ffff0000'} |
31 | 19 | end |
32 | 20 | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/range_test.rb
... | ... | @@ -1,20 +0,0 @@ |
1 | -require "test_helper" | |
2 | - | |
3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | |
4 | - | |
5 | -class RangeTest < ActiveSupport::TestCase | |
6 | - | |
7 | - def setup | |
8 | - @hash = RangeFixtures.amloc_bad_hash | |
9 | - @range = RangeFixtures.amloc_bad | |
10 | - end | |
11 | - | |
12 | - should 'create range from hash' do | |
13 | - assert_equal @range, Kalibro::Entities::Range.from_hash(@hash) | |
14 | - end | |
15 | - | |
16 | - should 'convert range to hash' do | |
17 | - assert_equal @hash, @range.to_hash | |
18 | - end | |
19 | - | |
20 | -end |
... | ... | @@ -0,0 +1,20 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | |
4 | + | |
5 | +class RangeTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = RangeFixtures.range_bad_hash | |
9 | + @range = RangeFixtures.range_bad | |
10 | + end | |
11 | + | |
12 | + should 'create range from hash' do | |
13 | + assert_equal @hash[:label], Kalibro::Range.new(@hash).label | |
14 | + end | |
15 | + | |
16 | + should 'convert range to hash' do | |
17 | + assert_equal @hash, @range.to_hash | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |