Class: Contacts::Outlook
Instance Method Summary collapse
- #contacts ⇒ Object
-
#initialize(file) ⇒ Outlook
constructor
A new instance of Outlook.
Methods inherited from Base
#connect, #connected?, #login, #password
Constructor Details
#initialize(file) ⇒ Outlook
Returns a new instance of Outlook.
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 |
# File 'lib/contacts/outlook.rb', line 6 def initialize(file) @contact_file = Array.new file = file.respond_to?(:read) ? file.read : file file.each_line do |line| @contact_file << CSV.parse(line)[0] end @full_name = false @header_indexes = Hash.new @header_indexes[:email_address] = Array.new headers = @contact_file[0] @contact_file = @contact_file[1, @contact_file.length] headers.each_with_index do |header, i| if header.match(/^Name$/) @full_name = true @header_indexes[:full_name] = i elsif header.match(/^First Name/) @header_indexes[:first_name] = i elsif header.match(/^Last Name/) @header_indexes[:last_name] = i elsif header.match(/E-mail/) @header_indexes[:email_address] << i end end end |
Instance Method Details
#contacts ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/contacts/outlook.rb', line 34 def contacts contacts = Array.new @contact_file.each_with_index do |line, i| contacts[i] = Array.new unless contacts[i] if(@full_name) contacts[i][0] = line[@header_indexes[:full_name]] else contacts[i][0] = "#{line[@header_indexes[:first_name]]} #{line[@header_indexes[:last_name]]}" end @header_indexes[:email_address].each do |index| if line[index] && !contacts[i][1] contacts[i][1] = line[index] end end end contacts end |