Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add draft csv reader

  • Loading branch information...
commit 896c5c7bfc7b9851511d0736aa8fcfe2ad422d82 1 parent b68bc56
@coreyhaines coreyhaines authored
Showing with 25 additions and 0 deletions.
  1. +25 −0 reader_csv.rb
View
25 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
+
Please sign in to comment.
Something went wrong with that request. Please try again.