class Tipper::Builder

Public Class Methods

new(total:, gratuity: @total = total) click to toggle source
# File lib/tipper/builder.rb, line 3
def initialize total:, gratuity:
    @total = total
    @gratuity = gratuity
end

Public Instance Methods

calculation() click to toggle source
# File lib/tipper/builder.rb, line 25
def calculation
    @total += @total * (gratuity.to_f / 100)
end
generate() click to toggle source
# File lib/tipper/builder.rb, line 8
def generate 
    return calculation if number_based?
    string_based
end
number_based() click to toggle source
# File lib/tipper/builder.rb, line 13
def number_based
    (@gratuity.is_a? Numeric) || (@gratuity.integer?)
end
string_based() click to toggle source
# File lib/tipper/builder.rb, line 17
def string_based
    case @gratuity.downcase
    when 'high'      then calculation 25
    when 'standard'  then calculation 18 
    when 'low'       then calculation 15 
    end
end