Class: EventReporter::LoadNewFile
- Inherits:
-
Object
- Object
- EventReporter::LoadNewFile
- Defined in:
- lib/event_reporter/load_new_file.rb
Instance Method Summary collapse
- #clean_city(dirty_city) ⇒ Object
- #clean_email(dirty_email) ⇒ Object
- #clean_first_name(dirty_first_name) ⇒ Object
- #clean_last_name(dirty_last_name) ⇒ Object
- #clean_phone(dirty_phone) ⇒ Object
- #clean_reg_date ⇒ Object
- #clean_state(dirty_state) ⇒ Object
- #clean_street(dirty_street) ⇒ Object
- #clean_zipcode(zipcode) ⇒ Object
-
#initialize(user_input) ⇒ LoadNewFile
constructor
A new instance of LoadNewFile.
- #parse_file(filename) ⇒ Object
- #returner ⇒ Object
Constructor Details
#initialize(user_input) ⇒ LoadNewFile
Returns a new instance of LoadNewFile.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/event_reporter/load_new_file.rb', line 8 def initialize(user_input) @people = [] @contents =" " @filename = "" if user_input[-4..-1] == ".csv" @filename = user_input elsif user_input == "load" puts"Loading Default File" @filename="event_attendees.csv" else puts "Bro, that is not a CSV or i cannot find the file...\n \n Loading Default File." @filename="event_attendees.csv" end default_filename = File.join(File.dirname(__FILE__),"../../bin/", @filename) @contents = CSV.open(default_filename, headers: true, header_converters: :symbol ) parse_file(@filename) end |
Instance Method Details
#clean_city(dirty_city) ⇒ Object
42 43 44 |
# File 'lib/event_reporter/load_new_file.rb', line 42 def clean_city(dirty_city) dirty_city.to_s.downcase end |
#clean_email(dirty_email) ⇒ Object
58 59 60 |
# File 'lib/event_reporter/load_new_file.rb', line 58 def clean_email(dirty_email) dirty_email.to_s.downcase end |
#clean_first_name(dirty_first_name) ⇒ Object
66 67 68 |
# File 'lib/event_reporter/load_new_file.rb', line 66 def clean_first_name(dirty_first_name) dirty_first_name.to_s.downcase end |
#clean_last_name(dirty_last_name) ⇒ Object
62 63 64 |
# File 'lib/event_reporter/load_new_file.rb', line 62 def clean_last_name(dirty_last_name) dirty_last_name.to_s.downcase end |
#clean_phone(dirty_phone) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/event_reporter/load_new_file.rb', line 31 def clean_phone(dirty_phone) phone = dirty_phone.scan(/[0-9]/).join if phone.length == 10 "(#{phone[0..2]})#{phone[3..5]}-#{phone[6..9]}" elsif phone.length ==11 && phone[0]==1 "(#{phone[1..3]})#{phone[4..6]}-#{phone[7..10]}" else "(000)000-0000" end end |
#clean_reg_date ⇒ Object
50 51 52 |
# File 'lib/event_reporter/load_new_file.rb', line 50 def clean_reg_date puts "puts clean reg date" end |
#clean_state(dirty_state) ⇒ Object
46 47 48 |
# File 'lib/event_reporter/load_new_file.rb', line 46 def clean_state(dirty_state) dirty_state.to_s.downcase end |
#clean_street(dirty_street) ⇒ Object
54 55 56 |
# File 'lib/event_reporter/load_new_file.rb', line 54 def clean_street(dirty_street) dirty_street.to_s.downcase end |
#clean_zipcode(zipcode) ⇒ Object
27 28 29 |
# File 'lib/event_reporter/load_new_file.rb', line 27 def clean_zipcode(zipcode) zipcode.to_s.rjust(5,"0")[0..4] end |
#parse_file(filename) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/event_reporter/load_new_file.rb', line 71 def parse_file(filename) @people = [] @contents.each do |row| person = {} person[:id] = row[0] person[:regdate] = row[:regdate] person[:first_name] = clean_first_name(row[:first_name]) person[:last_name] = clean_last_name(row[:last_name]) person[:email] = clean_email(row[:email_address]) person[:phone] = clean_phone(row[:homephone]) person[:street] = clean_street(row[:street]) person[:city] = clean_city(row[:city]) person[:state] = clean_state(row[:state]) person[:zipcode] = clean_zipcode(row[:zipcode]) @people << person end puts "Loaded #{@people.count} Records from '#{filename}'..." end |
#returner ⇒ Object
90 91 92 |
# File 'lib/event_reporter/load_new_file.rb', line 90 def returner @people end |