Skip to content

Instantly share code, notes, and snippets.

@gschorkopf
Last active August 29, 2015 13:55
Show Gist options
  • Select an option

  • Save gschorkopf/8771777 to your computer and use it in GitHub Desktop.

Select an option

Save gschorkopf/8771777 to your computer and use it in GitHub Desktop.
require_relative './file_parser'
require_relative './file_reader'
require_relative './receipt'
class ReceiptPrinter
attr_reader :output
def initialize
remove_existing_output
@output = create_receipts
end
def print
output.each_with_index do |line, index|
File.open("output.txt", "a+"){|f| f << "Output #{counter + 1}:\n" }
output.summary.each do |summary|
File.open("output.txt", "a+"){|f| f << "#{summary}\n" }
end
File.open("output.txt", "a+"){|f| f << "Sales Taxes: #{(line.sales_tax_total).round(2)}\nTotal: #{(line.subtotal).round(2)}\n\n" }
end
end
private
def remove_existing_output
File.delete("output.txt") if File.exists?("output.txt")
end
def create_receipts
input = FileParser.parse_file(FileReader.read_file)
input.map { |i| Receipt.new(i) }
end
end
r = ReceiptPrinter.new
r.print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment