Class: SriTippy::Builder

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

Instance Method Summary collapse

Constructor Details

#initialize(total:, gratuity:) ⇒ Builder

Returns a new instance of Builder.



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

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

Instance Method Details

#calculation(gratuity = @gratuity) ⇒ Object



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

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

#generateObject



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

def generate
	return calculation if number_based?
	string_based
end

#number_based?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/sri_tippy/builder.rb', line 13

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

#string_basedObject



17
18
19
20
21
22
23
# File 'lib/sri_tippy/builder.rb', line 17

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