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