Skip to content

Instantly share code, notes, and snippets.

@igrabes
Created September 29, 2011 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrabes/1250134 to your computer and use it in GitHub Desktop.
Save igrabes/1250134 to your computer and use it in GitHub Desktop.
CSV Parser
require 'csv'
class CsvReader
def initialize
@number_of_entries = []
end
def read_in_csv_data(csv_file_name)
CSV.foreach(csv_file_name, headers: true ) do |row|
@number_of_entries << ValueInCells.new( row["Amount"])
end
end
def total_value_in_cells
sum = 0.0
if @number_of_entries == 0
@number_of_entries.each {|cells| sum == sum }
else
@number_of_entries.each {|cells| sum += cells.value }
sum
end
end
def number_of_each_isbn
end
end
class ValueInCells
attr_accessor :value
def initialize(value)
@value = Float(value)
end
end
require_relative 'csv_reader'
reader = CsvReader.new
ARGV.each do |csv_file_name|
STDERR.puts "Processing #{csv_file_name}"
reader.read_in_csv_data(csv_file_name)
end
puts "Total value = #{reader.total_value_in_cells}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment