Create a gist now

Instantly share code, notes, and snippets.

lean kata.... err, less lean
# pommes, mele same as apples
@shop = {
apples: 100,
cherries: 75,
bananas: 150,
pommes: 100,
mele: 100
}
def reset_totals
@total = 0
@cherry_count = 0
@cherry_discount = 20
@banana_count = 0
@banana_discount = 150
@pommes_count = 0
@pommes_discount = 100
@meles_count = 0
@meles_discount = 50
end
def cherry_pricing
@cherry_count += 1
if @cherry_count % 2 == 0
puts 'modded'
@total -= @cherry_discount
end
end
def banana_pricing
@banana_count += 1
if @banana_count % 2 == 0
puts 'modded banana'
@total -= @banana_discount
end
end
def pommes_pricing
@pommes_count += 1
if @pommes_count % 3 == 0
puts 'modded pommes'
@total -= @pommes_discount
end
end
def meles_pricing
@meles_count += 1
if @meles_count % 2 == 0
puts 'modded meles'
@total -= @meles_discount
end
end
def csv_runner inputarr
inputarr.each do |input|
single_item input
end
reset_totals
end
def single_item input
@total += @shop[input.to_sym] # unless shop[input].nil?
cherry_pricing if input == 'cherries'
banana_pricing if input == 'bananas'
pommes_pricing if input == 'pommes'
meles_pricing if input == 'mele'
puts @total
end
reset_totals
while csvinput = gets.chomp
inputarr = csvinput.split(',')
if inputarr.length == 1
# single line version
single_item csvinput
else
# csv baby
csv_runner inputarr
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment