Class: Tippy::Builder

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

Instance Method Summary collapse

Constructor Details

#initialize(total:, gratuity:) ⇒ Builder

Returns a new instance of Builder.



3
4
5
6
# File 'lib/tippy_jay/builder.rb', line 3

def initialize total:, gratuity:
  @total = total
  @gratuity = gratuity
end

Instance Method Details

#generateObject



8
9
10
11
# File 'lib/tippy_jay/builder.rb', line 8

def generate
  return total_calculator if number_based?
  string_based
end

#number_based?Boolean

Returns:

  • (Boolean)


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

def number_based?
  (@gratuity.is_a? Numeric) || (@gratuity.match? /^[0-9]\d*(\.\d+)?$/)
end

#string_basedObject



13
14
15
16
17
18
19
# File 'lib/tippy_jay/builder.rb', line 13

def string_based
  case @gratuity.downcase
  when 'high'     then total_calculator 25
  when 'standard' then total_calculator 18
  when 'low'    then total_calculator 15
  end
end

#total_calculator(gratuity = @gratuity) ⇒ Object



25
26
27
# File 'lib/tippy_jay/builder.rb', line 25

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