Skip to content

Instantly share code, notes, and snippets.

@JuarezLustosa
Last active October 6, 2020 16:35
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 JuarezLustosa/ccdcb71117a2ac56e7a4eb300e070d7c to your computer and use it in GitHub Desktop.
Save JuarezLustosa/ccdcb71117a2ac56e7a4eb300e070d7c to your computer and use it in GitHub Desktop.
class Rate
attr_accessor :credit_card, :value,
def self.calculate(credit_card, value)
new(credit_card, value).calculate
end
def initialize(credit_card, value)
@credit_card = credit_card
@value = value.to_i
end
def calculate
rate = "blank"
case credit_card
when 'master_card'
rate = calculate_rate(0.1)
when 'visa'
rate = calculate_rate(0.2)
when 'elo'
rate = calculate_rate(0.5)
else
rate = 'Credit Card brand unknow'
end
puts "The rate of #{credit_card} is #{rate}"
end
private def calculate_rate(credit_rate)
value - (value * credit_rate)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment