class CalculateTip
Public Class Methods
new(amount = nil, tip = "15", currencie = nil)
click to toggle source
# File lib/calculate-tip.rb, line 4 def initialize(amount = nil, tip = "15", currencie = nil) if amount.to_f < 0 or tip.to_f < 0 raise ArgumentError.new("Amount is negative!") end @amount = amount.to_f @tip = tip.to_f @currencie = currencie.to_s end
Public Instance Methods
calculate()
click to toggle source
# File lib/calculate-tip.rb, line 22 def calculate calc_tip = (@amount * @tip) / 100 total_amount = @amount + calc_tip puts "Total amount with tip: " + total_amount.to_s + " " + @currencie puts "Tip amount: " + calc_tip.to_s + " " + @currencie puts "Calculation with external API " external_api = ExternalApi.new(@amount, @tip) puts external_api.calculate return end
get_amount()
click to toggle source
# File lib/calculate-tip.rb, line 14 def get_amount @amount end
get_tip()
click to toggle source
# File lib/calculate-tip.rb, line 18 def get_tip @tip end