Class: CalculateTip
- Inherits:
-
Object
- Object
- CalculateTip
- Defined in:
- lib/calculate-tip.rb
Instance Method Summary collapse
- #calculate ⇒ Object
- #get_amount ⇒ Object
- #get_tip ⇒ Object
-
#initialize(amount = nil, tip = "15", currencie = nil) ⇒ CalculateTip
constructor
A new instance of CalculateTip.
Constructor Details
#initialize(amount = nil, tip = "15", currencie = nil) ⇒ CalculateTip
4 5 6 7 8 9 10 11 12 |
# 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 |
Instance Method Details
#calculate ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
14 15 16 |
# File 'lib/calculate-tip.rb', line 14 def get_amount @amount end |
#get_tip ⇒ Object
18 19 20 |
# File 'lib/calculate-tip.rb', line 18 def get_tip @tip end |