Last active
September 4, 2015 20:34
-
-
Save Queeniebee/df01e7832231080f7789 to your computer and use it in GitHub Desktop.
syntax error, unexpected keyword_end, expecting end-of-input
This file contains 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
Class Receipt | |
def initialize(filename) | |
@items = Array.new | |
@filename = filename | |
File.foreach(@filename) { |line| @items.push(line) } | |
@dict = {:food => %w("chocolates", "chocolate", "donut", "apple", "fruit", "wine"), :medical => %w("pills", "syringe", "medicine", "salve", "bandage" ), :book => %w("books", "book") } | |
@tax = Float.new | |
@item = String.new | |
@num = Integer.new | |
@price = Float.new | |
end | |
def sort_line_item(*item) | |
purchase = Array.new | |
item.each do |i| | |
purchase = i.split | |
@num = purchase[0].to_i | |
@item = purchase[-3] | |
@price = purchase[-1].to_f | |
purchase[-2] = ":" | |
end | |
return purchase.join(' ') | |
end | |
def cost_of_item(*item) | |
if @num.integer? && @num > 0 | |
return cost = @num * @price | |
else | |
return "not a number, check receipt" | |
end | |
end | |
def imported(*item) | |
return item.include?('imported') | |
end | |
def import_tax(*item, cost) | |
if item.include?(@dict[:food]) || item.include?(@dict[:medical]) || item.include?(@dict[:book]) | |
@tax = (5 * cost).round(2) / 100.0 | |
else | |
@tax = (15 * cost) / 100.0 | |
end | |
cost += @tax | |
cost = cost.round(2) | |
return cost | |
end | |
def domestic_tax(*item, cost) | |
@tax = (10 * cost).round(2) / 100.0 | |
cost += @tax | |
cost = cost.round(2) | |
return cost | |
end | |
end | |
r1 = Receipt.new(ARGV.first) | |
rl.sort_line_item(*@items) | |
cost = cost_of_item(*@items) | |
if r1.imported(*@items) | |
import = r1.import_tax(*@items, cost) | |
else | |
domestic = r1.domestic_tax(*@items, cost) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment