Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated awards, update_quality, update_quality_spec files, so that al… #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
97 changes: 96 additions & 1 deletion award.rb
Original file line number Diff line number Diff line change
@@ -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

44 changes: 1 addition & 43 deletions update_quality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion update_quality_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down