Class: Tippy::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/tippy_alfred/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(total:, gratuity:) ⇒ Builder

Returns a new instance of Builder.



11
12
13
14
# File 'lib/tippy_alfred/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/tippy_alfred/builder.rb', line 33

def calculation gratuity = @gratuity
  @total += @total * (gratuity.to_f / 100)
end

#generateObject



16
17
18
19
# File 'lib/tippy_alfred/builder.rb', line 16

def generate
  return calculation if number_based?
  string_based
end

#number_based?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/tippy_alfred/builder.rb', line 21

def number_based?
  (@gratuity.is_a? Numeric) || (@gratuity.integer?)
end

#string_basedObject



25
26
27
28
29
30
31
# File 'lib/tippy_alfred/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