Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

lean kata.... err, less lean

View lean.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
# 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
Something went wrong with that request. Please try again.