Class: Tippy::Builder
- Inherits:
-
Object
- Object
- Tippy::Builder
- Defined in:
- lib/tippy_jay/builder.rb
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(total:, gratuity:) ⇒ Builder
constructor
A new instance of Builder.
- #number_based? ⇒ Boolean
- #string_based ⇒ Object
- #total_calculator(gratuity = @gratuity) ⇒ Object
Constructor Details
#initialize(total:, gratuity:) ⇒ Builder
Returns a new instance of Builder.
3 4 5 6 |
# File 'lib/tippy_jay/builder.rb', line 3 def initialize total:, gratuity: @total = total @gratuity = gratuity end |
Instance Method Details
#generate ⇒ Object
8 9 10 11 |
# File 'lib/tippy_jay/builder.rb', line 8 def generate return total_calculator if number_based? string_based end |
#number_based? ⇒ Boolean
21 22 23 |
# File 'lib/tippy_jay/builder.rb', line 21 def number_based? (@gratuity.is_a? Numeric) || (@gratuity.match? /^[0-9]\d*(\.\d+)?$/) end |
#string_based ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/tippy_jay/builder.rb', line 13 def string_based case @gratuity.downcase when 'high' then total_calculator 25 when 'standard' then total_calculator 18 when 'low' then total_calculator 15 end end |
#total_calculator(gratuity = @gratuity) ⇒ Object
25 26 27 |
# File 'lib/tippy_jay/builder.rb', line 25 def total_calculator gratuity = @gratuity @total += @total * (gratuity.to_f / 100) end |