Class: Tippy::Builder
- Inherits:
-
Object
- Object
- Tippy::Builder
- Defined in:
- lib/tippy/builder.rb
Overview
Builder class for the tippy gem
Instance Method Summary collapse
- #calculation(gratuity = @gratuity) ⇒ Object
- #generate ⇒ Object
-
#initialize(total:, gratuity:) ⇒ Builder
constructor
A new instance of Builder.
- #number_based? ⇒ Boolean
- #string_based ⇒ Object
Constructor Details
#initialize(total:, gratuity:) ⇒ Builder
Returns a new instance of Builder.
12 13 14 15 |
# File 'lib/tippy/builder.rb', line 12 def initialize(total:, gratuity:) @total = total @gratuity = gratuity end |
Instance Method Details
#calculation(gratuity = @gratuity) ⇒ Object
35 36 37 |
# File 'lib/tippy/builder.rb', line 35 def calculation(gratuity = @gratuity) @total += @total * (gratuity.to_f / 100) end |
#generate ⇒ Object
17 18 19 20 21 |
# File 'lib/tippy/builder.rb', line 17 def generate return calculation if number_based? string_based end |
#number_based? ⇒ Boolean
23 24 25 |
# File 'lib/tippy/builder.rb', line 23 def number_based? (@gratuity.is_a? Numeric) || @gratuity.integer? end |
#string_based ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/tippy/builder.rb', line 27 def string_based case @gratuity.downcase when 'high' then calculation 25 when 'standard' then calculation 18 when 'low' then calculation 15 end end |