Class: Tipsty::Builder
- Inherits:
-
Object
- Object
- Tipsty::Builder
- Defined in:
- lib/tipsty/builder.rb
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.
10 11 12 13 |
# File 'lib/tipsty/builder.rb', line 10 def initialize total:, gratuity: @total = total @gratuity = gratuity end |
Instance Method Details
#calculation(gratuity = @gratuity) ⇒ Object
32 33 34 |
# File 'lib/tipsty/builder.rb', line 32 def calculation gratuity = @gratuity @total += @total * (gratuity.to_f / 100) end |
#generate ⇒ Object
15 16 17 18 |
# File 'lib/tipsty/builder.rb', line 15 def generate return calculation if number_based? string_based end |
#number_based? ⇒ Boolean
20 21 22 |
# File 'lib/tipsty/builder.rb', line 20 def number_based? (@gratuity.is_a? Numeric) || (@gratuity.integer?) end |
#string_based ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/tipsty/builder.rb', line 24 def string_based case @gratuity.downcase when 'high' then calculation 25 when 'standard' then calculation 18 when 'low' then calculation 15 end end |