fruit_to_lime 2.3.1 → 2.3.2

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.
Files changed (42) hide show
  1. data/bin/fruit_to_lime +24 -24
  2. data/lib/fruit_to_lime/email_helper.rb +10 -0
  3. data/lib/fruit_to_lime/errors.rb +4 -1
  4. data/lib/fruit_to_lime/excel_helper.rb +10 -0
  5. data/lib/fruit_to_lime/global_phone.json +6571 -0
  6. data/lib/fruit_to_lime/model/class_settings.rb +7 -4
  7. data/lib/fruit_to_lime/model/coworker.rb +2 -2
  8. data/lib/fruit_to_lime/model/coworker_reference.rb +10 -0
  9. data/lib/fruit_to_lime/model/deal.rb +12 -3
  10. data/lib/fruit_to_lime/model/note.rb +42 -1
  11. data/lib/fruit_to_lime/model/organization.rb +29 -7
  12. data/lib/fruit_to_lime/model/person.rb +26 -9
  13. data/lib/fruit_to_lime/model/rootmodel.rb +145 -9
  14. data/lib/fruit_to_lime/phone_helper.rb +74 -0
  15. data/lib/fruit_to_lime.rb +4 -1
  16. data/spec/class_settings_spec.rb +23 -3
  17. data/spec/deal_spec.rb +22 -12
  18. data/spec/helpers/email_helper_spec.rb +32 -0
  19. data/spec/helpers/phone_helper_spec.rb +97 -0
  20. data/spec/helpers/roo_helper_spec.rb +10 -10
  21. data/spec/note_spec.rb +55 -0
  22. data/spec/organization_spec.rb +57 -0
  23. data/spec/person_spec.rb +15 -6
  24. data/spec/rootmodel_spec.rb +133 -7
  25. data/spec/spec_helper.rb +24 -24
  26. data/templates/csv/Gemfile +5 -5
  27. data/templates/csv/Rakefile.rb +7 -7
  28. data/templates/csv/convert.rb +2 -2
  29. data/templates/csv/spec/spec_helper.rb +24 -24
  30. data/templates/excel/Gemfile +6 -6
  31. data/templates/excel/Rakefile.rb +7 -7
  32. data/templates/excel/convert.rb +2 -2
  33. data/templates/excel/lib/tomodel.rb +167 -29
  34. data/templates/excel/spec/spec_helper.rb +20 -20
  35. data/templates/excel/spec/tomodel_spec.rb +18 -18
  36. data/templates/excel/template.xlsx +0 -0
  37. data/templates/sqlserver/Gemfile +6 -6
  38. data/templates/sqlserver/Rakefile.rb +7 -7
  39. data/templates/sqlserver/convert.rb +2 -2
  40. data/templates/sqlserver/spec/spec_helper.rb +20 -20
  41. data/templates/sqlserver/spec/tomodel_spec.rb +9 -9
  42. metadata +47 -2
@@ -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,64 +1,202 @@
1
1
  require 'fruit_to_lime'
2
2
  require 'roo'
3
3
 
4
- class ToModel
5
- def to_organization(row)
6
- organization = FruitToLime::Organization.new()
7
- # Map properties
8
- organization.integration_id = row['Id']
9
- organization.name = row['Name']
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.
10
12
 
11
- return organization
12
- end
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
13
21
 
22
+ class Converter
14
23
  def configure(model)
15
- # add custom field to your model here. Custom fields can be
24
+ # Add custom field to your model here. Custom fields can be
16
25
  # added to organization, deal and person. Valid types are
17
26
  # :String and :Link. If no type is specified :String is used
18
27
  # as default.
19
28
 
20
- model.settings.with_deal do |deal|
21
- deal.set_custom_field( { :integrationid => 'discount_url', :title => 'Rabatt url', :type => :Link } )
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)
22
40
  end
23
41
  end
24
42
 
25
- def to_model(organization_file_name)
26
- # from excel to csv
27
- organization_file_data = Roo::Excelx.new(organization_file_name)
43
+ def to_coworker(row)
44
+ coworker = FruitToLime::Coworker.new()
28
45
 
29
- model = FruitToLime::RootModel.new
30
- configure model
31
- rows = FruitToLime::RooHelper.new(organization_file_data).rows
32
- rows.each do |row|
33
- model.organizations.push(to_organization(row))
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']
34
54
  end
35
- return model
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
+ # *** TODO:
79
+ #
80
+ # Set organization properties from the row.
81
+
82
+ organization.name = row['Namn']
83
+
84
+ return organization
85
+ end
86
+
87
+ def to_person(row)
88
+ person = FruitToLime::Person.new()
89
+
90
+ # *** TODO:
91
+ #
92
+ # Set person properties from the row.
93
+
94
+ person.parse_name_to_firstname_lastname_se(row['Namn'])
95
+ if FruitToLime::EmailHelper.is_valid?(row['Email'])
96
+ person.email = row['Email']
97
+ end
98
+ person.mobile_phone_number, person.direct_phone_number =
99
+ FruitToLime::PhoneHelper.parse_numbers(row['Telefon'], [",", "/", "\\"])
100
+
101
+ return person
102
+ end
103
+
104
+ def to_note(row)
105
+ note = FruitToLime::Note.new()
106
+
107
+ # *** TODO:
108
+ #
109
+ # Set note properties from the row.
110
+
111
+ note.organization = @rootmodel.find_organization_by_integration_id(row['ID'])
112
+ note.created_by = @rootmodel.find_coworker_by_integration_id(row['Skapad av'])
113
+ note.text = row['Text']
114
+ note.date = row['Skapad den']
115
+
116
+ return note
117
+ end
118
+
119
+ def to_model(in_data_filename)
120
+ # *** TODO:
121
+ #
122
+ # Modify the name of the sheets. Or add/remove sheets based on
123
+ # your file.
124
+
125
+ # First we read each sheet from the excel file into separate
126
+ # variables
127
+ excel_workbook = FruitToLime::ExcelHelper.Open(in_data_filename)
128
+ organization_rows = excel_workbook.rows_for_sheet 'Foretag'
129
+ person_rows = excel_workbook.rows_for_sheet 'Kontaktperson'
130
+ note_rows = excel_workbook.rows_for_sheet 'Anteckningar'
131
+ coworker_rows = excel_workbook.rows_for_sheet 'Medarbetare'
132
+
133
+ # Then we create a rootmodel that should contain all data that
134
+ # should be exported to LIME Go.
135
+ @rootmodel = FruitToLime::RootModel.new
136
+
137
+ # And configure the model if we have any custom fields
138
+ configure @rootmodel
139
+
140
+ # Now start to read data from the excel file and add to the
141
+ # rootmodel. We begin with coworkers since they are referenced
142
+ # from everywhere (orgs, deals, notes)
143
+ coworker_rows.each do |row|
144
+ @rootmodel.add_coworker(to_coworker(row))
145
+ end
146
+
147
+ # Then create organizations, they are only referenced by
148
+ # coworkers.
149
+ organization_rows.each do |row|
150
+ @rootmodel.add_organization(to_organization(row))
151
+ end
152
+
153
+ # Add people and link them to their organizations
154
+ person_rows.each do |row|
155
+ # People are special since they are not added directly to
156
+ # the root model
157
+ import_person_to_organization(row)
158
+ end
159
+
160
+ # Deals can connected to coworkers, organizations and people.
161
+ # deal_rows.each do |row|
162
+ # @rootmodel.add_deal(to_deal(row))
163
+ # end
164
+
165
+ # Notes must be owned by a coworker and the be added to
166
+ # organizations and notes and might refernce a person
167
+ note_rows.each do |row|
168
+ @rootmodel.add_note(to_note(row))
169
+ end
170
+
171
+ return @rootmodel
36
172
  end
37
173
  end
38
174
 
175
+ # You don't need to change anything below this line.
176
+
39
177
  require "thor"
40
178
  require "fileutils"
41
179
  require 'pathname'
42
180
 
43
181
  class Cli < Thor
44
- desc "to_go ORGANIZATION FILE", "Converts excel file to Go xml format. ORGANIZATIONS is path to input file. FILE is output file where Go xml will go."
45
- def to_go(organizations, file = nil)
46
- file = 'export.xml' if file == nil
47
- toModel = ToModel.new()
48
- model = toModel.to_model(organizations)
182
+ 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."
183
+ def to_go(in_data_filename, go_data_filename = nil)
184
+ go_data_filename = 'go-data.xml' if go_data_filename == nil
185
+ converter = Converter.new()
186
+ model = converter.to_model(in_data_filename)
49
187
  error = model.sanity_check
50
188
  if error.empty?
51
189
  validation_errors = model.validate
52
190
 
53
191
  if validation_errors.empty?
54
- model.serialize_to_file(file)
55
- puts "'#{organizations}' has been converted into '#{file}'."
192
+ model.serialize_to_file(go_data_filename)
193
+ puts "'#{in_data_filename}' has been converted into '#{go_data_filename}'."
56
194
  else
57
- puts "'#{organizations}' could not be converted due to"
195
+ puts "'#{in_data_filename}' could not be converted due to"
58
196
  puts validation_errors
59
197
  end
60
198
  else
61
- puts "'#{organizations}' could not be converted due to"
199
+ puts "'#{in_data_filename}' could not be converted due to"
62
200
  puts error
63
201
  end
64
202
  end
@@ -1,20 +1,20 @@
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/autorun'
4
-
5
- RSpec.configure do |config|
6
- # ## Mock Framework
7
- #
8
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
9
- #
10
- # config.mock_with :mocha
11
- # config.mock_with :flexmock
12
- # config.mock_with :rr
13
-
14
- # Run specs in random order to surface order dependencies. If you find an
15
- # order dependency and want to debug it, you can fix the order by providing
16
- # the seed, which is printed after each run.
17
- # --seed 1234
18
- config.order = "random"
19
- end
20
-
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/autorun'
4
+
5
+ RSpec.configure do |config|
6
+ # ## Mock Framework
7
+ #
8
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
9
+ #
10
+ # config.mock_with :mocha
11
+ # config.mock_with :flexmock
12
+ # config.mock_with :rr
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = "random"
19
+ end
20
+
@@ -1,18 +1,18 @@
1
- # Encoding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'tomodel'
5
-
6
-
7
- describe 'Model' do
8
- before(:all) do
9
- toModel = ToModel.new
10
- samplefile =File.join(File.dirname(__FILE__), 'sample_data', 'sample.xlsx')
11
- @model = toModel.to_model(samplefile)
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
18
-
1
+ # Encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'tomodel'
5
+
6
+ describe 'Model' do
7
+ before(:all) do
8
+ converter = Converter.new
9
+ samplefile = File.join(File.dirname(__FILE__), '..', 'template.xlsx')
10
+ @rootmodel = converter.to_model(samplefile)
11
+ end
12
+
13
+ it "will find something with a name" do
14
+ organization = @rootmodel.organizations[0]
15
+ organization.name.length.should > 0
16
+ end
17
+ end
18
+
Binary file
@@ -1,6 +1,6 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'rspec'
4
- gem 'thor'
5
- gem 'fruit_to_lime'
6
- gem 'tiny_tds'
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'thor'
5
+ gem 'fruit_to_lime'
6
+ gem 'tiny_tds'
@@ -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,20 +1,20 @@
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/autorun'
4
-
5
- RSpec.configure do |config|
6
- # ## Mock Framework
7
- #
8
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
9
- #
10
- # config.mock_with :mocha
11
- # config.mock_with :flexmock
12
- # config.mock_with :rr
13
-
14
- # Run specs in random order to surface order dependencies. If you find an
15
- # order dependency and want to debug it, you can fix the order by providing
16
- # the seed, which is printed after each run.
17
- # --seed 1234
18
- config.order = "random"
19
- end
20
-
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/autorun'
4
+
5
+ RSpec.configure do |config|
6
+ # ## Mock Framework
7
+ #
8
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
9
+ #
10
+ # config.mock_with :mocha
11
+ # config.mock_with :flexmock
12
+ # config.mock_with :rr
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = "random"
19
+ end
20
+
@@ -1,9 +1,9 @@
1
- # Encoding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'tomodel'
5
-
6
- describe 'Model' do
7
-
8
- end
9
-
1
+ # Encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'tomodel'
5
+
6
+ describe 'Model' do
7
+
8
+ end
9
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fruit_to_lime
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-05-07 00:00:00.000000000 Z
14
+ date: 2014-05-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: iso_country_codes
@@ -77,6 +77,38 @@ dependencies:
77
77
  - - ! '>='
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: sixarm_ruby_email_address_validation
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: global_phone
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
80
112
  - !ruby/object:Gem::Dependency
81
113
  name: nokogiri
82
114
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +168,9 @@ extensions: []
136
168
  extra_rdoc_files: []
137
169
  files:
138
170
  - lib/fruit_to_lime/csv_helper.rb
171
+ - lib/fruit_to_lime/email_helper.rb
139
172
  - lib/fruit_to_lime/errors.rb
173
+ - lib/fruit_to_lime/excel_helper.rb
140
174
  - lib/fruit_to_lime/model/address.rb
141
175
  - lib/fruit_to_lime/model/class_settings.rb
142
176
  - lib/fruit_to_lime/model/coworker.rb
@@ -152,6 +186,7 @@ files:
152
186
  - lib/fruit_to_lime/model/settings.rb
153
187
  - lib/fruit_to_lime/model/tag.rb
154
188
  - lib/fruit_to_lime/model_helpers.rb
189
+ - lib/fruit_to_lime/phone_helper.rb
155
190
  - lib/fruit_to_lime/roo_helper.rb
156
191
  - lib/fruit_to_lime/serialize_helper.rb
157
192
  - lib/fruit_to_lime/templating.rb
@@ -174,21 +209,27 @@ files:
174
209
  - templates/excel/spec/sample_data/sample.xlsx
175
210
  - templates/excel/spec/spec_helper.rb
176
211
  - templates/excel/spec/tomodel_spec.rb
212
+ - templates/excel/template.xlsx
177
213
  - templates/sqlserver/convert.rb
178
214
  - templates/sqlserver/Gemfile
179
215
  - templates/sqlserver/lib/tomodel.rb
180
216
  - templates/sqlserver/Rakefile.rb
181
217
  - templates/sqlserver/spec/spec_helper.rb
182
218
  - templates/sqlserver/spec/tomodel_spec.rb
219
+ - lib/fruit_to_lime/global_phone.json
183
220
  - spec/address_spec.rb
184
221
  - spec/class_settings_spec.rb
185
222
  - spec/coworker_spec.rb
186
223
  - spec/custom_field_spec.rb
187
224
  - spec/deal_spec.rb
188
225
  - spec/helpers/csv_helper_spec.rb
226
+ - spec/helpers/email_helper_spec.rb
227
+ - spec/helpers/phone_helper_spec.rb
189
228
  - spec/helpers/roo_helper_spec.rb
190
229
  - spec/helpers/serialize_helper_spec.rb
191
230
  - spec/helpers/xsd_validate_spec.rb
231
+ - spec/note_spec.rb
232
+ - spec/organization_spec.rb
192
233
  - spec/person_spec.rb
193
234
  - spec/rootmodel_spec.rb
194
235
  - spec/spec_helper.rb
@@ -224,9 +265,13 @@ test_files:
224
265
  - spec/custom_field_spec.rb
225
266
  - spec/deal_spec.rb
226
267
  - spec/helpers/csv_helper_spec.rb
268
+ - spec/helpers/email_helper_spec.rb
269
+ - spec/helpers/phone_helper_spec.rb
227
270
  - spec/helpers/roo_helper_spec.rb
228
271
  - spec/helpers/serialize_helper_spec.rb
229
272
  - spec/helpers/xsd_validate_spec.rb
273
+ - spec/note_spec.rb
274
+ - spec/organization_spec.rb
230
275
  - spec/person_spec.rb
231
276
  - spec/rootmodel_spec.rb
232
277
  - spec/spec_helper.rb