Skip to content

Commit

Permalink
Add draft csv reader
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyhaines committed May 16, 2011
1 parent b68bc56 commit 896c5c7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions reader_csv.rb
@@ -0,0 +1,25 @@
def read_events file_name
first_row = true
names = []
events = []
CSV.foreach(file_name + ".csv") do |row|
if first_row
names = row
first_row = false
else
event_hash = {}
row.zip((0..(row.size - 1))).each do |field,position|
if names[position] == "date"
event_hash[names[position]] = Time.parse(field)
elsif names[position] == "complexity"
event_hash[names[position]] = field.to_f
else
event_hash[names[position]] = field
end
end
events << CodeEvent.new(event_hash)
end
end
events
end

0 comments on commit 896c5c7

Please sign in to comment.