contact_csv 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -1
- data/Manifest.txt +0 -3
- data/README.txt +50 -8
- data/lib/contact_csv.rb +0 -1
- data/lib/contact_csv/contact.rb +11 -77
- data/lib/contact_csv/contact_csv.rb +0 -10
- data/lib/contact_csv/contact_manager.rb +35 -26
- data/lib/contact_csv/lookup_tables/lookup_table.rb +20 -13
- data/lib/contact_csv/lookup_tables/outlook_csv.rb +106 -104
- data/lib/contact_csv/version.rb +1 -1
- data/test/test_contact.rb +6 -8
- data/test/test_contact_manager.rb +17 -3
- data/website/index.html +5 -5
- data/website/index.txt +3 -3
- metadata +2 -7
- data/lib/contact_csv/importer.rb +0 -18
- data/test/test_contact_csv.rb +0 -12
- data/test/test_importer.rb +0 -18
data/History.txt
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
== 0.0
|
1
|
+
== 0.2.0 2008-02-07
|
2
|
+
|
3
|
+
* 1 major enhancement
|
4
|
+
* Removed the Importer class because it wasn't needed. Added the functionality to the ContactManager class
|
5
|
+
* Beefed up the documentation
|
6
|
+
|
7
|
+
== 0.1.0 2008-02-05
|
2
8
|
|
3
9
|
* 1 major enhancement:
|
4
10
|
* Initial release
|
data/Manifest.txt
CHANGED
@@ -9,7 +9,6 @@ lib/contact_csv.rb
|
|
9
9
|
lib/contact_csv/contact.rb
|
10
10
|
lib/contact_csv/contact_csv.rb
|
11
11
|
lib/contact_csv/contact_manager.rb
|
12
|
-
lib/contact_csv/importer.rb
|
13
12
|
lib/contact_csv/lookup_tables/lookup_table.rb
|
14
13
|
lib/contact_csv/lookup_tables/outlook_csv.rb
|
15
14
|
lib/contact_csv/version.rb
|
@@ -23,10 +22,8 @@ tasks/website.rake
|
|
23
22
|
test/outlook_contacts.csv
|
24
23
|
test/outlook_contacts_dos.csv
|
25
24
|
test/test_contact.rb
|
26
|
-
test/test_contact_csv.rb
|
27
25
|
test/test_contact_manager.rb
|
28
26
|
test/test_helper.rb
|
29
|
-
test/test_importer.rb
|
30
27
|
test/test_lookup_table.rb
|
31
28
|
website/index.html
|
32
29
|
website/index.txt
|
data/README.txt
CHANGED
@@ -1,20 +1,62 @@
|
|
1
1
|
# === ContactCsv
|
2
|
+
#
|
3
|
+
# ==== Supported CSV
|
4
|
+
# * Outlook 2003 CSV (Windows)
|
2
5
|
#
|
3
6
|
# ==== Reading in CSV
|
4
7
|
#
|
5
|
-
#
|
8
|
+
# The two class methods are used to read in a CSV file of contacts exported by email clients such as Outlook or GMail.
|
9
|
+
# Both methods return an Array of Contact objects.
|
6
10
|
#
|
7
|
-
#
|
11
|
+
# contact_manager = ContactCsv::ContactManager.new
|
8
12
|
#
|
9
|
-
#
|
13
|
+
# contact_manager.read('/path/to/file.csv')
|
14
|
+
# or
|
15
|
+
# contact_manager.parse('csv,data,string')
|
10
16
|
#
|
11
17
|
# ==== Getting the contacts
|
12
18
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
19
|
+
# contact_manager.contacts.each do |contact|
|
20
|
+
# puts contact.name
|
21
|
+
# puts contact.email
|
22
|
+
# puts contact.extras['Spouse']
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# See the Contact class for a complete list of attributes.
|
26
|
+
#
|
27
|
+
#
|
28
|
+
# ==== Lookup Tables
|
29
|
+
#
|
30
|
+
# A lookup table is used to map the csv columns to Contact class attributes. You can create your own lookup tables
|
31
|
+
# by using the LookupTable class and passing it in inside an array to the ContactManager class.
|
32
|
+
#
|
33
|
+
# # These are the column headers in the csv
|
34
|
+
# headers = ["First Name","Last Name","Email Address"]
|
35
|
+
#
|
36
|
+
# # These map the column headers to the attribute of the Contact class
|
37
|
+
# legend = {
|
38
|
+
# 'First Name' => :first_name,
|
39
|
+
# 'Last Name ' => :last_name,
|
40
|
+
# 'Email Address' => :email
|
41
|
+
# }
|
42
|
+
#
|
43
|
+
# lookup_table = LookupTable.new(headers, legend)
|
44
|
+
#
|
45
|
+
# # The lookup table is passed into the ContactManager
|
46
|
+
# contact_manager = ContactCsv::ContactManager.new([lookup_table])
|
47
|
+
# or
|
48
|
+
# contact_manager.lookup_tables << lookup_table
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# If you think you have composed a good lookup table email it to me (mwhuss@gmail.com) and I will include it in the gem.
|
52
|
+
#
|
53
|
+
#
|
54
|
+
# ==== To Do
|
55
|
+
# * Add lookup table for Outlook 2003 CSV (DOS)
|
56
|
+
# * Add lookup table for GMail CSV
|
17
57
|
#
|
18
|
-
# See the Contact class for a complete list of attributes.
|
19
58
|
#
|
20
59
|
#
|
60
|
+
|
61
|
+
|
62
|
+
|
data/lib/contact_csv.rb
CHANGED
@@ -3,7 +3,6 @@ $:.unshift File.dirname(__FILE__)
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'fastercsv'
|
5
5
|
require 'contact_csv/contact_csv.rb'
|
6
|
-
require 'contact_csv/importer.rb'
|
7
6
|
require 'contact_csv/contact.rb'
|
8
7
|
require 'contact_csv/contact_manager.rb'
|
9
8
|
require 'contact_csv/lookup_tables/lookup_table.rb'
|
data/lib/contact_csv/contact.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
# === Contact
|
2
2
|
#
|
3
|
-
# Object that represents a Contact from an address book
|
3
|
+
# Object that represents a Contact from an address book. This class is meant to support the most common attributes.
|
4
4
|
#
|
5
5
|
class ContactCsv::Contact
|
6
6
|
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :first_name, :middle_name, :last_name, :email, :title, :extras
|
8
8
|
|
9
|
+
# Initializes a Contact objest and will take a hash of the attributes with values
|
10
|
+
#
|
11
|
+
# Contact.new(:first_name => "Willy", :last_name => "Wonka")
|
9
12
|
def initialize(attributes={})
|
10
13
|
@extras = {}
|
11
14
|
@first_name = attributes[:first_name]
|
@@ -15,88 +18,19 @@ class ContactCsv::Contact
|
|
15
18
|
@title = attributes[:title]
|
16
19
|
end
|
17
20
|
|
21
|
+
# Returns a hash of all attributes that could not be mapped to a Contact class attribute
|
18
22
|
def extras
|
19
23
|
@extras
|
20
24
|
end
|
21
25
|
|
26
|
+
# Adds an unmappable attribute
|
22
27
|
def add_extra(extra)
|
23
28
|
@extras.merge!(extra)
|
24
29
|
end
|
25
30
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# attr_accessor :name, :email, :address, :notes, :email2, :email3, :mobile_phone, :pager,
|
31
|
-
# :company, :job_title, :home_phone, :home_phone2, :home_fax, :home_address,
|
32
|
-
# :business_phone, :business_phone2, :business_fax, :business_address,
|
33
|
-
# :other_phone, :other_fax, :other_address
|
34
|
-
#
|
35
|
-
# # Initilize takes in options hash and sets the local attributes
|
36
|
-
# def initialize(attributes={})
|
37
|
-
# @name = attributes[:name]
|
38
|
-
# @email = attributes[:email]
|
39
|
-
# @address = attributes[:address]
|
40
|
-
# @notes = attributes[:notes]
|
41
|
-
# @email2 = attributes[:email2]
|
42
|
-
# @email3 = attributes[:email3]
|
43
|
-
# @mobile_phone = attributes[:mobile_phone]
|
44
|
-
# @pager = attributes[:pager]
|
45
|
-
# @company = attributes[:company]
|
46
|
-
# @job_title = attributes[:job_title]
|
47
|
-
# @home_phone = attributes[:home_phone]
|
48
|
-
# @home_phone2 = attributes[:home_phone2]
|
49
|
-
# @home_fax = attributes[:home_fax]
|
50
|
-
# @home_address = attributes[:home_address]
|
51
|
-
# @business_phone = attributes[:business_phone]
|
52
|
-
# @business_phone2 = attributes[:business_phone2]
|
53
|
-
# @business_fax = attributes[:business_fax]
|
54
|
-
# @business_address = attributes[:business_address]
|
55
|
-
# @other_phone = attributes[:other_phone]
|
56
|
-
# @other_fax = attributes[:other_fax]
|
57
|
-
# @other_address = attributes[:other_address]
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# # Creates an Array of Contact objects from the FasterCSV Array
|
61
|
-
# def self.contacts(csv)
|
62
|
-
# contacts = []
|
63
|
-
# csv.each do |c|
|
64
|
-
# contacts << Contact.new(
|
65
|
-
# :name => c[0],
|
66
|
-
# :email => c[1],
|
67
|
-
# :address => c[2],
|
68
|
-
# :notes => c[3],
|
69
|
-
# :email2 => c[4],
|
70
|
-
# :email3 => c[5],
|
71
|
-
# :mobile_phone => c[6],
|
72
|
-
# :pager => c[7],
|
73
|
-
# :company => c[8],
|
74
|
-
# :job_title => c[9],
|
75
|
-
# :home_phone => c[10],
|
76
|
-
# :home_phone2 => c[11],
|
77
|
-
# :home_fax => c[12],
|
78
|
-
# :home_address => c[13],
|
79
|
-
# :business_phone => c[14],
|
80
|
-
# :business_phone2 => c[15],
|
81
|
-
# :business_fax => c[16],
|
82
|
-
# :business_address => c[17],
|
83
|
-
# :other_phone => c[18],
|
84
|
-
# :other_fax => c[19],
|
85
|
-
# :other_address => c[20]
|
86
|
-
# )
|
87
|
-
# end
|
88
|
-
# contacts
|
89
|
-
# end
|
90
|
-
#
|
91
|
-
# def empty?
|
92
|
-
# @name.nil? && @email.nil? && @address.nil? && @notes.nil? && @email2.nil? &&
|
93
|
-
# @email3.nil? && @mobile_phone.nil? && @pager.nil? && @company.nil? && @job_title.nil? &&
|
94
|
-
# @home_phone.nil? && @home_phone2.nil? && @home_fax.nil? && @home_address.nil? && @business_phone.nil? &&
|
95
|
-
# @business_phone2.nil? && @business_fax.nil? && @business_address.nil? && @other_phone.nil? && @other_fax.nil? && @other_address
|
96
|
-
# end
|
97
|
-
#
|
98
|
-
#
|
99
|
-
# def method_missing(method, *args)
|
100
|
-
# end
|
31
|
+
# First name and last name
|
32
|
+
def full_name
|
33
|
+
[@first_name, @last_name].join(' ')
|
34
|
+
end
|
101
35
|
|
102
36
|
end
|
@@ -1,13 +1,3 @@
|
|
1
|
-
# === ContactCsv
|
2
|
-
#
|
3
|
-
# ==== Reading in CSV
|
4
|
-
#
|
5
|
-
# The two class methods are used to read in a CSV file of contacts exported by email clients such as Outlook or GMail. Both methods return an Array of Contact objects.
|
6
|
-
#
|
7
|
-
# ContactCSV.read('/path/to/file.csv')
|
8
|
-
#
|
9
|
-
# ContactCSV.parse('csv,data,string')
|
10
|
-
#
|
11
1
|
module ContactCsv
|
12
2
|
module LookupTables
|
13
3
|
end
|
@@ -1,52 +1,61 @@
|
|
1
|
+
# === ContctManager
|
2
|
+
#
|
3
|
+
# The ContactManager handles finding the appropriate lookup table and creating the array of Contact objects
|
4
|
+
#
|
5
|
+
#
|
1
6
|
class ContactCsv::ContactManager
|
2
7
|
include ContactCsv
|
8
|
+
include ContactCsv::LookupTables
|
3
9
|
|
4
|
-
attr_accessor :contacts
|
10
|
+
attr_accessor :contacts, :lookup_tables
|
5
11
|
|
6
|
-
|
12
|
+
# Initializes a ContactManager, accepts an Array of LookupTables
|
13
|
+
def initialize(lookup_tables=[])
|
14
|
+
@lookup_tables = lookup_tables + [OutlookCsv.lookup_table]
|
15
|
+
@contacts = []
|
16
|
+
end
|
17
|
+
|
18
|
+
# Reads a CSV file and creates a contact list
|
19
|
+
def read(file_path)
|
20
|
+
csv = FasterCSV.read(file_path, :headers => true)
|
21
|
+
create_contacts(csv)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Reads a CSV string and creates a contact list
|
25
|
+
def parse(csv_string)
|
26
|
+
csv = FasterCSV.parse(csv_string, :headers => true)
|
27
|
+
create_contacts(csv)
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# Creates a contact list from a CSV object
|
34
|
+
def create_contacts(csv)
|
7
35
|
@contacts = []
|
8
|
-
|
9
36
|
lookup_table = find_lookup_table(csv, lookup_tables)
|
10
37
|
raise LookupTableNotFoundError if lookup_table.nil?
|
11
|
-
|
12
38
|
csv.each do |row|
|
13
39
|
c = Contact.new
|
14
|
-
|
15
40
|
row.each do |r|
|
16
41
|
col = lookup_table.lookup(r[0])
|
17
|
-
if !col.nil? && c.respond_to?(col.to_sym)
|
18
|
-
|
19
|
-
else
|
20
|
-
c.add_extra({ r[0] => r[1] })
|
21
|
-
end
|
22
|
-
|
42
|
+
c.send("#{col.to_s}=", r[1]) if !col.nil? && c.respond_to?(col.to_sym)
|
43
|
+
c.add_extra({ r[0] => r[1] })
|
23
44
|
end
|
24
|
-
|
25
|
-
contacts << c
|
45
|
+
@contacts << c
|
26
46
|
end
|
27
|
-
|
28
|
-
contacts
|
29
47
|
end
|
30
48
|
|
31
49
|
|
32
|
-
|
33
|
-
#def contacts
|
34
|
-
# []
|
35
|
-
#end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
private
|
40
|
-
|
50
|
+
# Determines the lookup table that matches the file
|
41
51
|
def find_lookup_table(csv, lookup_tables)
|
42
|
-
tables = lookup_tables + [
|
52
|
+
tables = lookup_tables + [OutlookCsv.lookup_table]
|
43
53
|
tables.each do |table|
|
44
54
|
return table if table.headers == csv.headers
|
45
55
|
end
|
46
56
|
return nil
|
47
57
|
end
|
48
58
|
|
49
|
-
|
50
59
|
class LookupTableNotFoundError < StandardError; end
|
51
60
|
|
52
61
|
end
|
@@ -1,20 +1,27 @@
|
|
1
|
+
# === LookupTable
|
2
|
+
#
|
3
|
+
# This class is so users can define their own lookup tables if it isn't supported natively. The headers is an
|
4
|
+
# Array of Strings that define the column names for the CSV file. Legend is a hash that maps the column strings
|
5
|
+
# to a Contact class attribute. Look at the Contact class for a list of available attributes.
|
6
|
+
#
|
7
|
+
#
|
1
8
|
class ContactCsv::LookupTables::LookupTable
|
2
9
|
|
3
|
-
|
10
|
+
attr_accessor :legend, :headers
|
4
11
|
|
5
|
-
|
12
|
+
# Initializes a LookupTable taking an Array of headers and a Hash that maps the column headers to the Contact object attributes
|
13
|
+
def initialize(headers, legend)
|
14
|
+
raise InvalidInputFormatError unless headers.is_a?(Array) && legend.is_a?(Hash)
|
15
|
+
@headers = headers
|
16
|
+
@legend = legend
|
17
|
+
end
|
6
18
|
|
7
19
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# Returns the corresponding Contact attribute mapped to the specific Outlook CSV column name
|
16
|
-
def lookup(column)
|
17
|
-
@legend[column]
|
18
|
-
end
|
20
|
+
# Returns the corresponding Contact attribute mapped to the specific Outlook CSV column name
|
21
|
+
def lookup(column)
|
22
|
+
@legend[column]
|
23
|
+
end
|
24
|
+
|
25
|
+
class InvalidInputFormatError < StandardError; end
|
19
26
|
|
20
27
|
end
|
@@ -1,114 +1,116 @@
|
|
1
1
|
# === OutlookCsv
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# Basic class to define the headers and legend for reading Outlook 2003 CSV (Windows) files
|
4
4
|
#
|
5
5
|
#
|
6
6
|
class ContactCsv::LookupTables::OutlookCsv
|
7
7
|
include ContactCsv::LookupTables
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
# Returns a Hash of how the columns map to the Contact attributes
|
10
|
+
def self.legend
|
11
|
+
{
|
12
|
+
'Title' => :title,
|
13
|
+
'First Name' => :first_name,
|
14
|
+
'Middle Name' => :middle_name,
|
15
|
+
'Last Name' => :last_name,
|
16
|
+
'E-mail Address' => :email
|
17
|
+
}
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
def self.lookup_table
|
111
|
-
LookupTable.new(self.headers, self.legend)
|
112
|
-
end
|
20
|
+
# Returns an Array of all the headers for a Outlook CSV file
|
21
|
+
def self.headers
|
22
|
+
[ "Title",
|
23
|
+
"First Name",
|
24
|
+
"Middle Name",
|
25
|
+
"Last Name",
|
26
|
+
"Suffix",
|
27
|
+
"Company",
|
28
|
+
"Department",
|
29
|
+
"Job Title",
|
30
|
+
"Business Street",
|
31
|
+
"Business Street 2",
|
32
|
+
"Business Street 3",
|
33
|
+
"Business City",
|
34
|
+
"Business State",
|
35
|
+
"Business Postal Code",
|
36
|
+
"Business Country",
|
37
|
+
"Home Street",
|
38
|
+
"Home Street 2",
|
39
|
+
"Home Street 3",
|
40
|
+
"Home City",
|
41
|
+
"Home State",
|
42
|
+
"Home Postal Code",
|
43
|
+
"Home Country",
|
44
|
+
"Other Street",
|
45
|
+
"Other Street 2",
|
46
|
+
"Other Street 3",
|
47
|
+
"Other City",
|
48
|
+
"Other State",
|
49
|
+
"Other Postal Code",
|
50
|
+
"Other Country",
|
51
|
+
"Assistant's Phone",
|
52
|
+
"Business Fax",
|
53
|
+
"Business Phone",
|
54
|
+
"Business Phone 2",
|
55
|
+
"Callback",
|
56
|
+
"Car Phone",
|
57
|
+
"Company Main Phone",
|
58
|
+
"Home Fax","Home Phone",
|
59
|
+
"Home Phone 2",
|
60
|
+
"ISDN",
|
61
|
+
"Mobile Phone",
|
62
|
+
"Other Fax",
|
63
|
+
"Other Phone",
|
64
|
+
"Pager",
|
65
|
+
"Primary Phone",
|
66
|
+
"Radio Phone",
|
67
|
+
"TTY/TDD Phone",
|
68
|
+
"Telex","Account",
|
69
|
+
"Anniversary",
|
70
|
+
"Assistant's Name",
|
71
|
+
"Billing Information",
|
72
|
+
"Birthday",
|
73
|
+
"Business Address PO Box",
|
74
|
+
"Categories","Children",
|
75
|
+
"Directory Server",
|
76
|
+
"E-mail Address",
|
77
|
+
"E-mail Type",
|
78
|
+
"E-mail Display Name",
|
79
|
+
"E-mail 2 Address",
|
80
|
+
"E-mail 2 Type",
|
81
|
+
"E-mail 2 Display Name",
|
82
|
+
"E-mail 3 Address",
|
83
|
+
"E-mail 3 Type",
|
84
|
+
"E-mail 3 Display Name",
|
85
|
+
"Gender",
|
86
|
+
"Government ID Number",
|
87
|
+
"Hobby",
|
88
|
+
"Home Address PO Box",
|
89
|
+
"Initials",
|
90
|
+
"Internet Free Busy",
|
91
|
+
"Keywords","Language",
|
92
|
+
"Location",
|
93
|
+
"Manager's Name",
|
94
|
+
"Mileage",
|
95
|
+
"Notes",
|
96
|
+
"Office Location",
|
97
|
+
"Organizational ID Number",
|
98
|
+
"Other Address PO Box",
|
99
|
+
"Priority","Private",
|
100
|
+
"Profession",
|
101
|
+
"Referred By",
|
102
|
+
"Sensitivity",
|
103
|
+
"Spouse",
|
104
|
+
"User 1",
|
105
|
+
"User 2",
|
106
|
+
"User 3",
|
107
|
+
"User 4",
|
108
|
+
"Web Page"]
|
109
|
+
end
|
113
110
|
|
111
|
+
# Returns a LookupTable object
|
112
|
+
def self.lookup_table
|
113
|
+
LookupTable.new(self.headers, self.legend)
|
114
114
|
end
|
115
|
+
|
116
|
+
end
|
data/lib/contact_csv/version.rb
CHANGED
data/test/test_contact.rb
CHANGED
@@ -25,13 +25,11 @@ class TestContact < Test::Unit::TestCase
|
|
25
25
|
assert_equal value, @contact.email
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
# assert_equal value, @contact.extras[key]
|
35
|
-
# end
|
28
|
+
def test_full_name
|
29
|
+
@contact.first_name = "Britany"
|
30
|
+
@contact.last_name = "Spears"
|
31
|
+
assert_equal "Britany Spears", @contact.full_name
|
32
|
+
end
|
33
|
+
|
36
34
|
|
37
35
|
end
|
@@ -3,10 +3,24 @@ require File.dirname(__FILE__) + '/test_helper.rb'
|
|
3
3
|
class TestContactManager < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
|
6
|
+
@cm = ContactCsv::ContactManager.new
|
7
|
+
@cm.read('test/outlook_contacts.csv')
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
-
|
10
|
+
def test_new
|
11
|
+
assert_not_nil ContactCsv::ContactManager.new
|
11
12
|
end
|
13
|
+
|
14
|
+
def test_read_contacts
|
15
|
+
assert_equal 5, @cm.contacts.size
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_first_contact
|
19
|
+
assert_equal "Michael", @cm.contacts.first.first_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_extra_field
|
23
|
+
assert_equal "http://www.www.com", @cm.contacts.first.extras['Web Page']
|
24
|
+
end
|
25
|
+
|
12
26
|
end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>ContactCsv</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/contact_csv"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/contact_csv" class="numbers">0.
|
36
|
+
<a href="http://rubyforge.org/projects/contact_csv" class="numbers">0.2.0</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘contact_csv’</h1>
|
39
39
|
|
@@ -58,9 +58,9 @@
|
|
58
58
|
|
59
59
|
<code>require 'contact_csv'</code>
|
60
60
|
<br />
|
61
|
-
<code>contacts = ContactCsv.parse("some,csv,string")</code><br />
|
61
|
+
<code>contacts = ContactCsv::Importer.parse("some,csv,string")</code><br />
|
62
62
|
or<br />
|
63
|
-
<code>contacts = ContactCsv.read("/path/to/contacts.csv") #=> Array of Contact objects</code><br /><br />
|
63
|
+
<code>contacts = ContactCsv::Importer.read("/path/to/contacts.csv") #=> Array of Contact objects</code><br /><br />
|
64
64
|
<code>contacts.first.first_name #=> "Marshall"</code><br />
|
65
65
|
<code>contacts.first.last_name #=> "Huss"</code><br />
|
66
66
|
<code>contacts.first.email #=> "mwhuss@gmail.com"</code>
|
@@ -94,9 +94,9 @@ or<br />
|
|
94
94
|
<h2>Contact</h2>
|
95
95
|
|
96
96
|
|
97
|
-
<p>Comments are welcome. Send an email to <a href="mailto:mwhuss@gmail.com">Marshall Huss</a>
|
97
|
+
<p>Comments are welcome. Send an email to <a href="mailto:mwhuss@gmail.com">Marshall Huss</a> or post on the <a href="http://rubyforge.org/forum/?group_id=5488">forum</a></p>
|
98
98
|
<p class="coda">
|
99
|
-
<a href="mailto:mwhuss@gmail.com">Marshall Huss</a>,
|
99
|
+
<a href="mailto:mwhuss@gmail.com">Marshall Huss</a>, 7th February 2008<br>
|
100
100
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
101
101
|
</p>
|
102
102
|
</div>
|
data/website/index.txt
CHANGED
@@ -20,9 +20,9 @@ h3. Demonstration of usage
|
|
20
20
|
|
21
21
|
<code>require 'contact_csv'</code>
|
22
22
|
<br />
|
23
|
-
<code>contacts = ContactCsv.parse("some,csv,string")</code><br />
|
23
|
+
<code>contacts = ContactCsv::Importer.parse("some,csv,string")</code><br />
|
24
24
|
or<br />
|
25
|
-
<code>contacts = ContactCsv.read("/path/to/contacts.csv") #=> Array of Contact objects</code><br /><br />
|
25
|
+
<code>contacts = ContactCsv::Importer.read("/path/to/contacts.csv") #=> Array of Contact objects</code><br /><br />
|
26
26
|
<code>contacts.first.first_name #=> "Marshall"</code><br />
|
27
27
|
<code>contacts.first.last_name #=> "Huss"</code><br />
|
28
28
|
<code>contacts.first.email #=> "mwhuss@gmail.com"</code>
|
@@ -50,5 +50,5 @@ This code is free to use under the terms of the "MIT license":http://www.opensou
|
|
50
50
|
|
51
51
|
h2. Contact
|
52
52
|
|
53
|
-
Comments are welcome. Send an email to "Marshall Huss":mailto:mwhuss@gmail.com
|
53
|
+
Comments are welcome. Send an email to "Marshall Huss":mailto:mwhuss@gmail.com or post on the "forum":http://rubyforge.org/forum/?group_id=5488
|
54
54
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contact_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marshall Huss
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -46,7 +46,6 @@ files:
|
|
46
46
|
- lib/contact_csv/contact.rb
|
47
47
|
- lib/contact_csv/contact_csv.rb
|
48
48
|
- lib/contact_csv/contact_manager.rb
|
49
|
-
- lib/contact_csv/importer.rb
|
50
49
|
- lib/contact_csv/lookup_tables/lookup_table.rb
|
51
50
|
- lib/contact_csv/lookup_tables/outlook_csv.rb
|
52
51
|
- lib/contact_csv/version.rb
|
@@ -60,10 +59,8 @@ files:
|
|
60
59
|
- test/outlook_contacts.csv
|
61
60
|
- test/outlook_contacts_dos.csv
|
62
61
|
- test/test_contact.rb
|
63
|
-
- test/test_contact_csv.rb
|
64
62
|
- test/test_contact_manager.rb
|
65
63
|
- test/test_helper.rb
|
66
|
-
- test/test_importer.rb
|
67
64
|
- test/test_lookup_table.rb
|
68
65
|
- website/index.html
|
69
66
|
- website/index.txt
|
@@ -99,8 +96,6 @@ specification_version: 2
|
|
99
96
|
summary: Simple gem for reading in contact csv files that you can export from email clients like Outlook or GMail
|
100
97
|
test_files:
|
101
98
|
- test/test_contact.rb
|
102
|
-
- test/test_contact_csv.rb
|
103
99
|
- test/test_contact_manager.rb
|
104
100
|
- test/test_helper.rb
|
105
|
-
- test/test_importer.rb
|
106
101
|
- test/test_lookup_table.rb
|
data/lib/contact_csv/importer.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class ContactCsv::Importer
|
2
|
-
include ContactCsv
|
3
|
-
|
4
|
-
# Creates an Array of Contact objects from a CSV File
|
5
|
-
def self.read(file_path, lookup_tables=[])
|
6
|
-
csv = FasterCSV.read(file_path, :headers => true)
|
7
|
-
contact_manager = ContactManager.new(csv, lookup_tables)
|
8
|
-
contact_manager.contacts
|
9
|
-
end
|
10
|
-
|
11
|
-
# Creates an Array of Contact objects from a CSV String
|
12
|
-
def self.parse(csv_string, lookup_tables=[])
|
13
|
-
csv = FasterCSV.parse(csv_string, :headers => true)
|
14
|
-
contact_manager = ContactManager.new(csv, lookup_tables)
|
15
|
-
contact_manager.contacts
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
data/test/test_contact_csv.rb
DELETED
data/test/test_importer.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestImporter < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
def test_read
|
7
|
-
contacts = ContactCsv::Importer.read('test/outlook_contacts.csv')
|
8
|
-
assert_equal 5, contacts.size
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_first_contact
|
12
|
-
contacts = ContactCsv::Importer.read('test/outlook_contacts.csv')
|
13
|
-
c = contacts.first
|
14
|
-
assert_equal "Michael", c.first_name
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
end
|