Skip to content

Instantly share code, notes, and snippets.

@vtno
Last active August 11, 2020 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vtno/dbea8d331a0e01ecf2b9255ba03ff6b4 to your computer and use it in GitHub Desktop.
Save vtno/dbea8d331a0e01ecf2b9255ba03ff6b4 to your computer and use it in GitHub Desktop.
class QualityCalculator
def self.calculate_for_normal_award(award)
# normal award logic here
# which would update the quality of the award passed in
return award
end
def self.calculate_for_blue_first_award(award)
# blue first award logic here
# which would update the quality of the award passed in
return award
end
def self.calculate_for_blue_distinction_award(award)
# blue distinction award logic here
# which would update the quality of the award passed in
return award
end
def self.calculate(award)
return QualityCalculator.calculate_for_blue_distinction_award(award) if award.name == 'Blue Distinction'
return QualityCalculator.calculate_for_blue_first_award(award) if award.name == 'Blue First'
QualityCalculator.calculate_for_normal_award(award)
end
end
# then you can use it in update_quality method
def update_quality(awards)
awards.each { |award| QualityCalculator.calculate(award) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment