forked from michaelfeathers/repodepot-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader_csv.rb
More file actions
28 lines (28 loc) · 683 Bytes
/
reader_csv.rb
File metadata and controls
28 lines (28 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'csv'
require 'time'
require_relative 'code_event.rb'
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|
field_name = names[position]
if field_name == "date"
event_hash[field_name] = Time.parse(field)
elsif field_name == "complexity"
event_hash[field_name] = field.to_f
else
event_hash[field_name] = field
end
end
events << CodeEvent.new(event_hash)
end
end
events
end