fruit_to_lime 2.5.3 → 2.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) 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 -145
  13. data/lib/fruit_to_lime/model/deal_status.rb +12 -12
  14. data/lib/fruit_to_lime/model/note.rb +79 -79
  15. data/lib/fruit_to_lime/model/organization.rb +203 -197
  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 +338 -330
  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 -102
  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 -67
  38. data/spec/organization_spec.rb +103 -89
  39. data/spec/person_spec.rb +134 -134
  40. data/spec/rootmodel_spec.rb +277 -230
  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 -0
  49. data/templates/easy/Rakefile.rb +7 -0
  50. data/templates/easy/convert.rb +3 -0
  51. data/templates/easy/lib/tomodel.rb +330 -0
  52. data/templates/easy/spec/exporter_spec.rb +10 -0
  53. data/templates/easy/spec/sample_data/Company.txt +649 -0
  54. data/templates/easy/spec/spec_helper.rb +24 -0
  55. data/templates/excel/lib/tomodel.rb +207 -207
  56. data/templates/sqlserver/lib/tomodel.rb +79 -79
  57. metadata +10 -3
@@ -0,0 +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,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
@@ -1,79 +1,79 @@
1
- require 'fruit_to_lime'
2
- require 'roo'
3
- require 'date'
4
-
5
- class ToModel
6
- def to_organization(row)
7
- organization = FruitToLime::Organization.new()
8
- organization.integration_id = row['id']
9
- organization.name = row['name']
10
- return organization
11
- end
12
-
13
- def configure(model)
14
- # add custom field to your model here. Custom fields can be
15
- # added to organization, deal and person. Valid types are
16
- # :String and :Link. If no type is specified :String is used
17
- # as default.
18
-
19
- model.settings.with_deal do |deal|
20
- deal.set_custom_field( { :integrationid => 'discount_url', :title => 'Rabatt url', :type => :Link } )
21
- end
22
- end
23
-
24
- def to_model(organization_rows)
25
- model = FruitToLime::RootModel.new
26
- configure model
27
-
28
- organization_rows.each do |row|
29
- model.organizations.push(to_organization(row))
30
- end
31
-
32
- return model
33
- end
34
- end
35
-
36
- require "thor"
37
- require "fileutils"
38
- require 'pathname'
39
- require 'tiny_tds'
40
-
41
- class Cli < Thor
42
- desc "to_go", "Connects to sql server and queries for organizations to Go xml format. HOST, DATABASE, USERNAME and PASSWORD for Sql server connection. FILE is output file where Go xml will go."
43
- def to_go(host, database, username, password, file = nil)
44
- puts "Connecting to database #{database} on server #{host} as user #{username}"
45
- client = TinyTds::Client.new(
46
- :username => username,
47
- :password => password,
48
- :host => host,
49
- :database => database)
50
-
51
- organizationSql =
52
- "SELECT
53
- c.id,
54
- c.name,
55
- FROM
56
- company c"
57
-
58
- organization_rows = client.execute(organizationSql)
59
-
60
- file = 'export.xml' if file == nil
61
- tomodel = ToModel.new()
62
- model = tomodel.to_model(organization_rows)
63
- error = model.sanity_check
64
- if error.empty?
65
- validation_errors = model.validate
66
-
67
- if validation_errors.empty?
68
- model.serialize_to_file(file)
69
- puts "'#{organizations}' has been converted into '#{file}'."
70
- else
71
- puts "'#{organizations}' could not be converted due to"
72
- puts validation_errors
73
- end
74
- else
75
- puts "'#{organizations}' could not be converted due to"
76
- puts error
77
- end
78
- end
79
- end
1
+ require 'fruit_to_lime'
2
+ require 'roo'
3
+ require 'date'
4
+
5
+ class ToModel
6
+ def to_organization(row)
7
+ organization = FruitToLime::Organization.new()
8
+ organization.integration_id = row['id']
9
+ organization.name = row['name']
10
+ return organization
11
+ end
12
+
13
+ def configure(model)
14
+ # add custom field to your model here. Custom fields can be
15
+ # added to organization, deal and person. Valid types are
16
+ # :String and :Link. If no type is specified :String is used
17
+ # as default.
18
+
19
+ model.settings.with_deal do |deal|
20
+ deal.set_custom_field( { :integrationid => 'discount_url', :title => 'Rabatt url', :type => :Link } )
21
+ end
22
+ end
23
+
24
+ def to_model(organization_rows)
25
+ model = FruitToLime::RootModel.new
26
+ configure model
27
+
28
+ organization_rows.each do |row|
29
+ model.organizations.push(to_organization(row))
30
+ end
31
+
32
+ return model
33
+ end
34
+ end
35
+
36
+ require "thor"
37
+ require "fileutils"
38
+ require 'pathname'
39
+ require 'tiny_tds'
40
+
41
+ class Cli < Thor
42
+ desc "to_go", "Connects to sql server and queries for organizations to Go xml format. HOST, DATABASE, USERNAME and PASSWORD for Sql server connection. FILE is output file where Go xml will go."
43
+ def to_go(host, database, username, password, file = nil)
44
+ puts "Connecting to database #{database} on server #{host} as user #{username}"
45
+ client = TinyTds::Client.new(
46
+ :username => username,
47
+ :password => password,
48
+ :host => host,
49
+ :database => database)
50
+
51
+ organizationSql =
52
+ "SELECT
53
+ c.id,
54
+ c.name,
55
+ FROM
56
+ company c"
57
+
58
+ organization_rows = client.execute(organizationSql)
59
+
60
+ file = 'export.xml' if file == nil
61
+ tomodel = ToModel.new()
62
+ model = tomodel.to_model(organization_rows)
63
+ error = model.sanity_check
64
+ if error.empty?
65
+ validation_errors = model.validate
66
+
67
+ if validation_errors.empty?
68
+ model.serialize_to_file(file)
69
+ puts "'#{organizations}' has been converted into '#{file}'."
70
+ else
71
+ puts "'#{organizations}' could not be converted due to"
72
+ puts validation_errors
73
+ end
74
+ else
75
+ puts "'#{organizations}' could not be converted due to"
76
+ puts error
77
+ end
78
+ end
79
+ end