Class: EventReporter::CSVParser

Inherits:
Object
  • Object
show all
Defined in:
lib/event_reporter/csv_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ CSVParser

Returns a new instance of CSVParser.



3
4
5
6
7
8
9
# File 'lib/event_reporter/csv_parser.rb', line 3

def initialize(filename)
  csv_file = File.expand_path("../../../bin/#{filename}", __FILE__)
  throw(:top, "File not found :(") if !File.exists?(csv_file)
  @contents = CSV.open(csv_file,
                       :headers => true,
                       :header_converters => :symbol)
end

Instance Method Details

#parseObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/event_reporter/csv_parser.rb', line 11

def parse
  @contents.map do |line|
    last_name = Cleaners::clean_name(line[:last_name])
    first_name = Cleaners::clean_name(line[:first_name])
    email = Cleaners::clean_email(line[:email_address])
    zipcode = Cleaners::clean_zipcode(line[:zipcode])
    city = Cleaners::clean_city(line[:city])
    state = Cleaners::clean_state(line[:state])
    address = Cleaners::clean_address(line[:street])
    phone_number = Cleaners::clean_phone_number(line[:homephone])
    Attendee.new(last_name,
                 first_name,
                 email,
                 zipcode,
                 city,
                 state,
                 address,
                 phone_number
                 )
  end
end