-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_parser.rb
More file actions
37 lines (29 loc) · 742 Bytes
/
data_parser.rb
File metadata and controls
37 lines (29 loc) · 742 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
29
30
31
32
33
34
35
36
37
$LOAD_PATH << './'
require 'csv'
require 'elements'
module EventReporter
class DataParser
CSV_OPTIONS = {:headers => true, :header_converters => :symbol}
def initialize
@@loaded_data = []
end
def self.loaded_data
@@loaded_data
end
def self.valid_parameters_for_load?(parameters)
parameters[0] =~ /\.csv$/ || parameters[0].nil?
end
def self.load(filename, options = CSV_OPTIONS)
if filename.nil?
filename = "event_attendees.csv"
end
file = (CSV.open(filename, options))
loading_data(file)
end
def self.loading_data(file)
file.rewind
@@loaded_data = file.collect { |line| Element.new(line) }
puts "Data loaded"
end
end
end