outlook_importer 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{outlook_importer}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Frank Pr\303\266\303\237dorf, Thilo Utke"]
data/outlook_importer.rb CHANGED
@@ -2,14 +2,17 @@ require 'rubygems'
2
2
  require 'fastercsv'
3
3
 
4
4
  class OutlookImporter
5
- def initialize(mapping)
6
- @mapping = mapping.invert
7
- raise ArgumentError unless valid_arguments?
5
+ def initialize(mapping = nil)
6
+ if mapping
7
+ @mapping = mapping.invert
8
+ raise ArgumentError unless valid_arguments?
9
+ end
8
10
  end
9
11
 
10
12
  def read(file_path)
11
13
  separator = File.new(file_path).gets.match(/([,;])[^,;]+\n/)[1]
12
14
  @csv = FasterCSV.read(file_path, :headers => true, :col_sep => separator)
15
+ @mapping = find_lookup_table.invert unless @mapping
13
16
  assign_header_columns(@csv.headers)
14
17
  end
15
18
 
@@ -68,4 +71,27 @@ class OutlookImporter
68
71
  def joined_arguments?
69
72
  @joined_arguments ||= @header_column_indices.include?(:name)
70
73
  end
74
+
75
+ def find_lookup_table
76
+ lookup_tables.each do |key, mapping|
77
+ return mapping if mapping.values - @csv.headers == []
78
+ end
79
+ end
80
+
81
+ def lookup_tables
82
+ {
83
+ :livemail =>
84
+ {
85
+ :name => 'Name',
86
+ :email => 'E-Mail-Adresse'
87
+ },
88
+ :outlook =>
89
+ {
90
+ :firstname => 'Vorname',
91
+ :lastname => 'Nachname',
92
+ :email => 'E-Mail-Adresse'
93
+ }
94
+ }
95
+ end
96
+
71
97
  end
@@ -22,7 +22,20 @@ class OutlookImporterTest < Test::Unit::TestCase
22
22
  importer.read('livemail_de.csv')
23
23
 
24
24
  assert_equal importer.contacts.first, ["Robin Example", "robin@example.de"]
25
+ end
26
+
27
+ def test_read_outlook_contacts_without_providing_a_lookup_table
28
+ importer = OutlookImporter.new
29
+ importer.read('outlook_2007_de.csv')
30
+
31
+ assert_equal importer.contacts.first, ["Robin Example", "robin@example.de"]
32
+ end
33
+
34
+ def test_read_livemail_contacts_without_providing_a_lookup_table
35
+ importer = OutlookImporter.new
36
+ importer.read('livemail_de.csv')
25
37
 
38
+ assert_equal importer.contacts.first, ["Robin Example", "robin@example.de"]
26
39
  end
27
40
 
28
41
  def test_initilize_raise_invalid_argument_error_if_lookup_not_satisfied
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outlook_importer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Frank Pr\xC3\xB6\xC3\x9Fdorf, Thilo Utke"