diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..1c7ffd3 Binary files /dev/null and b/.DS_Store differ diff --git a/award.rb b/award.rb index 5208232..c941a22 100644 --- a/award.rb +++ b/award.rb @@ -1 +1,96 @@ -Award = Struct.new(:name, :expires_in, :quality) +# Award = Struct.new(:name, :expires_in, :quality) + +class Award + + attr_accessor :name, :expires_in, :quality + + def initialize(name, int_expires_in, int_quality) + @name = name + @expires_in = int_expires_in + @quality = int_quality + end + + def update_award + case @name + when 'Blue Compare' + update_blue_compare + when 'Blue Distinction Plus' + update_blue_distinction_plus + when 'Blue First' + update_blue_first + when 'Blue Star' + update_blue_star + when 'NORMAL ITEM' + update_normal_item + end + end + + private + + def expired? + @expires_in <= 0 + end + + def max_quality? + if @quality >= 50 + @quality = 50 + return true + else + return false + end + end + + def quality_larger_than_zero? + @quality > 0 + end + + def update_blue_compare + if expired? + @quality = 0 + elsif @expires_in <= 5 + @quality = @quality + 3 + elsif @expires_in <= 10 + @quality = @quality + 2 + else + @quality = @quality + 1 + end + max_quality? + @expires_in = @expires_in - 1 + end + + def update_blue_distinction_plus + @quality = 80 + end + + def update_blue_first + if !expired? + @quality = @quality + 1 + else + @quality = @quality + 2 + end + max_quality? + @expires_in = @expires_in - 1 + end + + def update_blue_star + if quality_larger_than_zero? + @quality = @quality - 2 + end + @expires_in = @expires_in - 1 + if expired? && quality_larger_than_zero? + @quality = @quality - 2 + end + end + + def update_normal_item + if quality_larger_than_zero? + @quality = @quality - 1 + end + @expires_in = expires_in - 1 + if expired? && quality_larger_than_zero? + @quality = @quality - 1 + end + end + +end + diff --git a/update_quality.rb b/update_quality.rb index bd1f10f..93f78ac 100644 --- a/update_quality.rb +++ b/update_quality.rb @@ -2,48 +2,6 @@ def update_quality(awards) awards.each do |award| - if award.name != 'Blue First' && award.name != 'Blue Compare' - if award.quality > 0 - if award.name != 'Blue Distinction Plus' - award.quality -= 1 - end - end - else - if award.quality < 50 - award.quality += 1 - if award.name == 'Blue Compare' - if award.expires_in < 11 - if award.quality < 50 - award.quality += 1 - end - end - if award.expires_in < 6 - if award.quality < 50 - award.quality += 1 - end - end - end - end - end - if award.name != 'Blue Distinction Plus' - award.expires_in -= 1 - end - if award.expires_in < 0 - if award.name != 'Blue First' - if award.name != 'Blue Compare' - if award.quality > 0 - if award.name != 'Blue Distinction Plus' - award.quality -= 1 - end - end - else - award.quality = award.quality - award.quality - end - else - if award.quality < 50 - award.quality += 1 - end - end - end + award.update_award end end diff --git a/update_quality_spec.rb b/update_quality_spec.rb index 973940d..879da5a 100644 --- a/update_quality_spec.rb +++ b/update_quality_spec.rb @@ -177,7 +177,6 @@ end context 'given a Blue Star award' do - before { pending } let(:name) { 'Blue Star' } before { award.expires_in.should == initial_expires_in-1 }