Created
July 16, 2014 20:11
-
-
Save skinofstars/820e66ffbf2576dca49b to your computer and use it in GitHub Desktop.
lean kata.... err, less lean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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