fruit_to_lime 2.5.5 → 2.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/lib/fruit_to_lime.rb +17 -17
  2. data/lib/fruit_to_lime/csv_helper.rb +47 -47
  3. data/lib/fruit_to_lime/email_helper.rb +10 -10
  4. data/lib/fruit_to_lime/errors.rb +16 -16
  5. data/lib/fruit_to_lime/excel_helper.rb +10 -10
  6. data/lib/fruit_to_lime/global_phone.json +6571 -6571
  7. data/lib/fruit_to_lime/model/address.rb +60 -60
  8. data/lib/fruit_to_lime/model/class_settings.rb +50 -50
  9. data/lib/fruit_to_lime/model/coworker.rb +76 -76
  10. data/lib/fruit_to_lime/model/coworker_reference.rb +33 -33
  11. data/lib/fruit_to_lime/model/customfield.rb +87 -87
  12. data/lib/fruit_to_lime/model/deal.rb +141 -141
  13. data/lib/fruit_to_lime/model/deal_status.rb +12 -12
  14. data/lib/fruit_to_lime/model/note.rb +80 -79
  15. data/lib/fruit_to_lime/model/organization.rb +203 -203
  16. data/lib/fruit_to_lime/model/person.rb +151 -151
  17. data/lib/fruit_to_lime/model/referencetosource.rb +45 -45
  18. data/lib/fruit_to_lime/model/relation.rb +23 -23
  19. data/lib/fruit_to_lime/model/rootmodel.rb +342 -338
  20. data/lib/fruit_to_lime/model/settings.rb +60 -60
  21. data/lib/fruit_to_lime/model/tag.rb +35 -35
  22. data/lib/fruit_to_lime/model_helpers.rb +54 -54
  23. data/lib/fruit_to_lime/phone_helper.rb +74 -74
  24. data/lib/fruit_to_lime/roo_helper.rb +72 -72
  25. data/lib/fruit_to_lime/serialize_helper.rb +186 -186
  26. data/lib/fruit_to_lime/templating.rb +52 -52
  27. data/spec/address_spec.rb +48 -48
  28. data/spec/class_settings_spec.rb +37 -37
  29. data/spec/coworker_spec.rb +94 -94
  30. data/spec/custom_field_spec.rb +22 -22
  31. data/spec/deal_spec.rb +101 -101
  32. data/spec/helpers/csv_helper_spec.rb +29 -29
  33. data/spec/helpers/email_helper_spec.rb +32 -32
  34. data/spec/helpers/phone_helper_spec.rb +97 -97
  35. data/spec/helpers/serialize_helper_spec.rb +249 -249
  36. data/spec/helpers/xsd_validate_spec.rb +58 -58
  37. data/spec/note_spec.rb +98 -98
  38. data/spec/organization_spec.rb +103 -103
  39. data/spec/person_spec.rb +134 -134
  40. data/spec/rootmodel_spec.rb +306 -277
  41. data/spec/templating_spec.rb +11 -11
  42. data/templates/csv/lib/tomodel.rb +230 -230
  43. data/templates/csv/spec/exporter_spec.rb +17 -17
  44. data/templates/csv/spec/sample_data/coworkers.csv +2 -2
  45. data/templates/csv/spec/sample_data/deals.csv +2 -2
  46. data/templates/csv/spec/sample_data/organizations.csv +2 -2
  47. data/templates/csv/spec/sample_data/persons.csv +2 -2
  48. data/templates/easy/Gemfile +5 -5
  49. data/templates/easy/Rakefile.rb +7 -7
  50. data/templates/easy/convert.rb +2 -2
  51. data/templates/easy/spec/exporter_spec.rb +10 -10
  52. data/templates/easy/spec/spec_helper.rb +24 -24
  53. data/templates/excel/lib/tomodel.rb +207 -207
  54. data/templates/sqlserver/lib/tomodel.rb +79 -79
  55. metadata +3 -3
@@ -1,17 +1,17 @@
1
- require 'spec_helper'
2
- require 'tomodel'
3
-
4
- describe 'Exporter' do
5
- before(:all) do
6
- exporter = Exporter.new
7
- organizations_file = File.join(File.dirname(__FILE__), 'sample_data', 'organizations.csv')
8
- coworkers_file = File.join(File.dirname(__FILE__), 'sample_data', 'coworkers.csv')
9
- persons_file = File.join(File.dirname(__FILE__), 'sample_data', 'persons.csv')
10
- deals_file = File.join(File.dirname(__FILE__), 'sample_data', 'deals.csv')
11
- @model = exporter.to_model(coworkers_file, organizations_file, persons_file, deals_file)
12
- end
13
- it "will find something with a name" do
14
- organization = @model.organizations[0]
15
- organization.name.length.should > 0
16
- end
17
- end
1
+ require 'spec_helper'
2
+ require 'tomodel'
3
+
4
+ describe 'Exporter' do
5
+ before(:all) do
6
+ exporter = Exporter.new
7
+ organizations_file = File.join(File.dirname(__FILE__), 'sample_data', 'organizations.csv')
8
+ coworkers_file = File.join(File.dirname(__FILE__), 'sample_data', 'coworkers.csv')
9
+ persons_file = File.join(File.dirname(__FILE__), 'sample_data', 'persons.csv')
10
+ deals_file = File.join(File.dirname(__FILE__), 'sample_data', 'deals.csv')
11
+ @model = exporter.to_model(coworkers_file, organizations_file, persons_file, deals_file)
12
+ end
13
+ it "will find something with a name" do
14
+ organization = @model.organizations[0]
15
+ organization.name.length.should > 0
16
+ end
17
+ end
@@ -1,2 +1,2 @@
1
- id;first_name;last_name
2
- 666;Evil;Elvis
1
+ id;first_name;last_name
2
+ 666;Evil;Elvis
@@ -1,2 +1,2 @@
1
- id;name;value;responsible_id;customer_id;customer_contact_id
2
- 333;Feta affären;10000;666;6;123
1
+ id;name;value;responsible_id;customer_id;customer_contact_id
2
+ 333;Feta affären;10000;666;6;123
@@ -1,2 +1,2 @@
1
- id;name;responsible_id
2
- 6;Alfs Mjukvaruutveckling;666
1
+ id;name;responsible_id
2
+ 6;Alfs Mjukvaruutveckling;666
@@ -1,2 +1,2 @@
1
- id;employer_id;first_name;last_name
2
- 123;6;Rune;Rebellion
1
+ id;employer_id;first_name;last_name
2
+ 123;6;Rune;Rebellion
@@ -1,5 +1,5 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'thor'
4
- gem 'fruit_to_lime'
5
- gem 'rspec'
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'thor'
4
+ gem 'fruit_to_lime'
5
+ gem 'rspec'
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env rake
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
7
- task :test => :spec
1
+ #!/usr/bin/env rake
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -1,3 +1,3 @@
1
- require "./lib/tomodel"
2
-
1
+ require "./lib/tomodel"
2
+
3
3
  Cli.start(ARGV)
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
2
- require 'tomodel'
3
-
4
- describe 'Exporter' do
5
- before(:all) do
6
- exporter = Exporter.new
7
- organizations_file = File.join(File.dirname(__FILE__), 'sample_data', 'company.txt')
8
- @model = exporter.to_model(nil, organizations_file, nil, nil, nil, nil, nil)
9
- end
10
- end
1
+ require 'spec_helper'
2
+ require 'tomodel'
3
+
4
+ describe 'Exporter' do
5
+ before(:all) do
6
+ exporter = Exporter.new
7
+ organizations_file = File.join(File.dirname(__FILE__), 'sample_data', 'company.txt')
8
+ @model = exporter.to_model(nil, organizations_file, nil, nil, nil, nil, nil)
9
+ end
10
+ end
@@ -1,24 +1,24 @@
1
- # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- #require File.expand_path("../../config/environment", __FILE__)
3
- #require 'rspec/rails'
4
- require 'rspec/autorun'
5
-
6
- # Requires supporting ruby files with custom matchers and macros, etc,
7
- # in spec/support/ and its subdirectories.
8
- #Dir[File.join(File.dirname(File.absolute_path(__FILE__)),"support/**/*.rb")].each { |f| require f }
9
-
10
- RSpec.configure do |config|
11
- # ## Mock Framework
12
- #
13
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
- #
15
- # config.mock_with :mocha
16
- # config.mock_with :flexmock
17
- # config.mock_with :rr
18
-
19
- # Run specs in random order to surface order dependencies. If you find an
20
- # order dependency and want to debug it, you can fix the order by providing
21
- # the seed, which is printed after each run.
22
- # --seed 1234
23
- config.order = "random"
24
- end
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ #require File.expand_path("../../config/environment", __FILE__)
3
+ #require 'rspec/rails'
4
+ require 'rspec/autorun'
5
+
6
+ # Requires supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ #Dir[File.join(File.dirname(File.absolute_path(__FILE__)),"support/**/*.rb")].each { |f| require f }
9
+
10
+ RSpec.configure do |config|
11
+ # ## Mock Framework
12
+ #
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ #
15
+ # config.mock_with :mocha
16
+ # config.mock_with :flexmock
17
+ # config.mock_with :rr
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ config.order = "random"
24
+ end
@@ -1,207 +1,207 @@
1
- require 'fruit_to_lime'
2
- require 'roo'
3
-
4
- # Customize this file to suit your input (excel) file.
5
- #
6
- # Documentation fruit_to_lime can be found at
7
- # http://rubygems.org/gems/fruit_to_lime
8
- #
9
- # Fruit_to_lime contains all objects in LIME Go such as organization,
10
- # people, deals, etc. What properties each object has is described in
11
- # the documentation.
12
-
13
- # *** TODO:
14
- #
15
- # This template will convert the file template.xlsx to LIME Go. You
16
- # should modify the Converted class suit your input file.
17
- #
18
- # Try this template with the template.xlsx file to generate a go.xml
19
- #file:
20
- # ruby convert.rb to_go template.xlsx lime-go.xml
21
-
22
- class Converter
23
- def configure(model)
24
- # Add custom field to your model here. Custom fields can be
25
- # added to organization, deal and person. Valid types are
26
- # :String and :Link. If no type is specified :String is used
27
- # as default.
28
-
29
- # model.settings.with_deal do |deal|
30
- # deal.set_custom_field( { :integrationid => 'discount_url', :title => 'Rabatt url', :type => :Link } )
31
- # end
32
- end
33
-
34
- def import_person_to_organization(row)
35
- person = to_person(row)
36
- organization = @rootmodel.find_organization_by_integration_id(row['ID'])
37
-
38
- if !organization.nil?
39
- organization.add_employee(person)
40
- end
41
- end
42
-
43
- def to_coworker(row)
44
- coworker = FruitToLime::Coworker.new()
45
-
46
- # *** TODO:
47
- #
48
- # Set coworker properties from the row.
49
-
50
- coworker.parse_name_to_firstname_lastname_se row['Namn/Titel']
51
- coworker.integration_id = row['Namn/Titel']
52
- if FruitToLime::EmailHelper.is_valid?(row['Email'])
53
- coworker.email = row['Email']
54
- end
55
-
56
- return coworker
57
- end
58
-
59
- def to_deal(row)
60
- deal = FruitToLime::Deal.new()
61
-
62
- # *** TODO:
63
- #
64
- # Set deal properties from the row.
65
-
66
- return deal
67
- end
68
-
69
- def to_organization(row)
70
- organization = FruitToLime::Organization.new()
71
- organization.set_tag "Importerad"
72
-
73
- # Integrationid is typically the id in the system that we are
74
- # getting the csv from. Must be set to be able to import the
75
- # same file more than once without creating duplicates
76
- organization.integration_id = row['ID']
77
-
78
- # Sets the organization's relation. Relation must be a value
79
- # from FruitToLime::Relation.
80
- organization.relation = FruitToLime::Relation::IsACustomer
81
-
82
- # *** TODO:
83
- #
84
- # Set organization properties from the row.
85
-
86
- organization.name = row['Namn']
87
-
88
- return organization
89
- end
90
-
91
- def to_person(row)
92
- person = FruitToLime::Person.new()
93
-
94
- # *** TODO:
95
- #
96
- # Set person properties from the row.
97
-
98
- person.parse_name_to_firstname_lastname_se(row['Namn'])
99
- if FruitToLime::EmailHelper.is_valid?(row['Email'])
100
- person.email = row['Email']
101
- end
102
- person.mobile_phone_number, person.direct_phone_number =
103
- FruitToLime::PhoneHelper.parse_numbers(row['Telefon'], [",", "/", "\\"])
104
-
105
- return person
106
- end
107
-
108
- def to_note(row)
109
- note = FruitToLime::Note.new()
110
-
111
- # *** TODO:
112
- #
113
- # Set note properties from the row.
114
-
115
- note.organization = @rootmodel.find_organization_by_integration_id(row['ID'])
116
- note.created_by = @rootmodel.find_coworker_by_integration_id(row['Skapad av'])
117
- note.text = row['Text']
118
- note.date = row['Skapad den']
119
-
120
- return note
121
- end
122
-
123
- def to_model(in_data_filename)
124
- # *** TODO:
125
- #
126
- # Modify the name of the sheets. Or add/remove sheets based on
127
- # your file.
128
-
129
- # First we read each sheet from the excel file into separate
130
- # variables
131
- excel_workbook = FruitToLime::ExcelHelper.Open(in_data_filename)
132
- organization_rows = excel_workbook.rows_for_sheet 'Foretag'
133
- person_rows = excel_workbook.rows_for_sheet 'Kontaktperson'
134
- note_rows = excel_workbook.rows_for_sheet 'Anteckningar'
135
- coworker_rows = excel_workbook.rows_for_sheet 'Medarbetare'
136
-
137
- # Then we create a rootmodel that should contain all data that
138
- # should be exported to LIME Go.
139
- @rootmodel = FruitToLime::RootModel.new
140
-
141
- # And configure the model if we have any custom fields
142
- configure @rootmodel
143
-
144
- # Now start to read data from the excel file and add to the
145
- # rootmodel. We begin with coworkers since they are referenced
146
- # from everywhere (orgs, deals, notes)
147
- coworker_rows.each do |row|
148
- @rootmodel.add_coworker(to_coworker(row))
149
- end
150
-
151
- # Then create organizations, they are only referenced by
152
- # coworkers.
153
- organization_rows.each do |row|
154
- @rootmodel.add_organization(to_organization(row))
155
- end
156
-
157
- # Add people and link them to their organizations
158
- person_rows.each do |row|
159
- # People are special since they are not added directly to
160
- # the root model
161
- import_person_to_organization(row)
162
- end
163
-
164
- # Deals can connected to coworkers, organizations and people.
165
- # deal_rows.each do |row|
166
- # @rootmodel.add_deal(to_deal(row))
167
- # end
168
-
169
- # Notes must be owned by a coworker and the be added to
170
- # organizations and notes and might refernce a person
171
- note_rows.each do |row|
172
- @rootmodel.add_note(to_note(row))
173
- end
174
-
175
- return @rootmodel
176
- end
177
- end
178
-
179
- # You don't need to change anything below this line.
180
-
181
- require "thor"
182
- require "fileutils"
183
- require 'pathname'
184
-
185
- class Cli < Thor
186
- desc "to_go IN_DATA_FILENAME GO_DATA_FILENAME", "Converts excel file to Go xml format. IN_DATA_FILENAME is path to input file. GO_DATA_FILENAME is output file where Go xml will go."
187
- def to_go(in_data_filename, go_data_filename = nil)
188
- go_data_filename = 'go-data.xml' if go_data_filename == nil
189
- converter = Converter.new()
190
- model = converter.to_model(in_data_filename)
191
- error = model.sanity_check
192
- if error.empty?
193
- validation_errors = model.validate
194
-
195
- if validation_errors.empty?
196
- model.serialize_to_file(go_data_filename)
197
- puts "'#{in_data_filename}' has been converted into '#{go_data_filename}'."
198
- else
199
- puts "'#{in_data_filename}' could not be converted due to"
200
- puts validation_errors
201
- end
202
- else
203
- puts "'#{in_data_filename}' could not be converted due to"
204
- puts error
205
- end
206
- end
207
- end
1
+ require 'fruit_to_lime'
2
+ require 'roo'
3
+
4
+ # Customize this file to suit your input (excel) file.
5
+ #
6
+ # Documentation fruit_to_lime can be found at
7
+ # http://rubygems.org/gems/fruit_to_lime
8
+ #
9
+ # Fruit_to_lime contains all objects in LIME Go such as organization,
10
+ # people, deals, etc. What properties each object has is described in
11
+ # the documentation.
12
+
13
+ # *** TODO:
14
+ #
15
+ # This template will convert the file template.xlsx to LIME Go. You
16
+ # should modify the Converted class suit your input file.
17
+ #
18
+ # Try this template with the template.xlsx file to generate a go.xml
19
+ #file:
20
+ # ruby convert.rb to_go template.xlsx lime-go.xml
21
+
22
+ class Converter
23
+ def configure(model)
24
+ # Add custom field to your model here. Custom fields can be
25
+ # added to organization, deal and person. Valid types are
26
+ # :String and :Link. If no type is specified :String is used
27
+ # as default.
28
+
29
+ # model.settings.with_deal do |deal|
30
+ # deal.set_custom_field( { :integrationid => 'discount_url', :title => 'Rabatt url', :type => :Link } )
31
+ # end
32
+ end
33
+
34
+ def import_person_to_organization(row)
35
+ person = to_person(row)
36
+ organization = @rootmodel.find_organization_by_integration_id(row['ID'])
37
+
38
+ if !organization.nil?
39
+ organization.add_employee(person)
40
+ end
41
+ end
42
+
43
+ def to_coworker(row)
44
+ coworker = FruitToLime::Coworker.new()
45
+
46
+ # *** TODO:
47
+ #
48
+ # Set coworker properties from the row.
49
+
50
+ coworker.parse_name_to_firstname_lastname_se row['Namn/Titel']
51
+ coworker.integration_id = row['Namn/Titel']
52
+ if FruitToLime::EmailHelper.is_valid?(row['Email'])
53
+ coworker.email = row['Email']
54
+ end
55
+
56
+ return coworker
57
+ end
58
+
59
+ def to_deal(row)
60
+ deal = FruitToLime::Deal.new()
61
+
62
+ # *** TODO:
63
+ #
64
+ # Set deal properties from the row.
65
+
66
+ return deal
67
+ end
68
+
69
+ def to_organization(row)
70
+ organization = FruitToLime::Organization.new()
71
+ organization.set_tag "Importerad"
72
+
73
+ # Integrationid is typically the id in the system that we are
74
+ # getting the csv from. Must be set to be able to import the
75
+ # same file more than once without creating duplicates
76
+ organization.integration_id = row['ID']
77
+
78
+ # Sets the organization's relation. Relation must be a value
79
+ # from FruitToLime::Relation.
80
+ organization.relation = FruitToLime::Relation::IsACustomer
81
+
82
+ # *** TODO:
83
+ #
84
+ # Set organization properties from the row.
85
+
86
+ organization.name = row['Namn']
87
+
88
+ return organization
89
+ end
90
+
91
+ def to_person(row)
92
+ person = FruitToLime::Person.new()
93
+
94
+ # *** TODO:
95
+ #
96
+ # Set person properties from the row.
97
+
98
+ person.parse_name_to_firstname_lastname_se(row['Namn'])
99
+ if FruitToLime::EmailHelper.is_valid?(row['Email'])
100
+ person.email = row['Email']
101
+ end
102
+ person.mobile_phone_number, person.direct_phone_number =
103
+ FruitToLime::PhoneHelper.parse_numbers(row['Telefon'], [",", "/", "\\"])
104
+
105
+ return person
106
+ end
107
+
108
+ def to_note(row)
109
+ note = FruitToLime::Note.new()
110
+
111
+ # *** TODO:
112
+ #
113
+ # Set note properties from the row.
114
+
115
+ note.organization = @rootmodel.find_organization_by_integration_id(row['ID'])
116
+ note.created_by = @rootmodel.find_coworker_by_integration_id(row['Skapad av'])
117
+ note.text = row['Text']
118
+ note.date = row['Skapad den']
119
+
120
+ return note
121
+ end
122
+
123
+ def to_model(in_data_filename)
124
+ # *** TODO:
125
+ #
126
+ # Modify the name of the sheets. Or add/remove sheets based on
127
+ # your file.
128
+
129
+ # First we read each sheet from the excel file into separate
130
+ # variables
131
+ excel_workbook = FruitToLime::ExcelHelper.Open(in_data_filename)
132
+ organization_rows = excel_workbook.rows_for_sheet 'Foretag'
133
+ person_rows = excel_workbook.rows_for_sheet 'Kontaktperson'
134
+ note_rows = excel_workbook.rows_for_sheet 'Anteckningar'
135
+ coworker_rows = excel_workbook.rows_for_sheet 'Medarbetare'
136
+
137
+ # Then we create a rootmodel that should contain all data that
138
+ # should be exported to LIME Go.
139
+ @rootmodel = FruitToLime::RootModel.new
140
+
141
+ # And configure the model if we have any custom fields
142
+ configure @rootmodel
143
+
144
+ # Now start to read data from the excel file and add to the
145
+ # rootmodel. We begin with coworkers since they are referenced
146
+ # from everywhere (orgs, deals, notes)
147
+ coworker_rows.each do |row|
148
+ @rootmodel.add_coworker(to_coworker(row))
149
+ end
150
+
151
+ # Then create organizations, they are only referenced by
152
+ # coworkers.
153
+ organization_rows.each do |row|
154
+ @rootmodel.add_organization(to_organization(row))
155
+ end
156
+
157
+ # Add people and link them to their organizations
158
+ person_rows.each do |row|
159
+ # People are special since they are not added directly to
160
+ # the root model
161
+ import_person_to_organization(row)
162
+ end
163
+
164
+ # Deals can connected to coworkers, organizations and people.
165
+ # deal_rows.each do |row|
166
+ # @rootmodel.add_deal(to_deal(row))
167
+ # end
168
+
169
+ # Notes must be owned by a coworker and the be added to
170
+ # organizations and notes and might refernce a person
171
+ note_rows.each do |row|
172
+ @rootmodel.add_note(to_note(row))
173
+ end
174
+
175
+ return @rootmodel
176
+ end
177
+ end
178
+
179
+ # You don't need to change anything below this line.
180
+
181
+ require "thor"
182
+ require "fileutils"
183
+ require 'pathname'
184
+
185
+ class Cli < Thor
186
+ desc "to_go IN_DATA_FILENAME GO_DATA_FILENAME", "Converts excel file to Go xml format. IN_DATA_FILENAME is path to input file. GO_DATA_FILENAME is output file where Go xml will go."
187
+ def to_go(in_data_filename, go_data_filename = nil)
188
+ go_data_filename = 'go-data.xml' if go_data_filename == nil
189
+ converter = Converter.new()
190
+ model = converter.to_model(in_data_filename)
191
+ error = model.sanity_check
192
+ if error.empty?
193
+ validation_errors = model.validate
194
+
195
+ if validation_errors.empty?
196
+ model.serialize_to_file(go_data_filename)
197
+ puts "'#{in_data_filename}' has been converted into '#{go_data_filename}'."
198
+ else
199
+ puts "'#{in_data_filename}' could not be converted due to"
200
+ puts validation_errors
201
+ end
202
+ else
203
+ puts "'#{in_data_filename}' could not be converted due to"
204
+ puts error
205
+ end
206
+ end
207
+ end