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