fruit_to_lime 2.5.5 → 2.5.6
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/lib/fruit_to_lime.rb +17 -17
- data/lib/fruit_to_lime/csv_helper.rb +47 -47
- data/lib/fruit_to_lime/email_helper.rb +10 -10
- data/lib/fruit_to_lime/errors.rb +16 -16
- data/lib/fruit_to_lime/excel_helper.rb +10 -10
- data/lib/fruit_to_lime/global_phone.json +6571 -6571
- data/lib/fruit_to_lime/model/address.rb +60 -60
- data/lib/fruit_to_lime/model/class_settings.rb +50 -50
- data/lib/fruit_to_lime/model/coworker.rb +76 -76
- data/lib/fruit_to_lime/model/coworker_reference.rb +33 -33
- data/lib/fruit_to_lime/model/customfield.rb +87 -87
- data/lib/fruit_to_lime/model/deal.rb +141 -141
- data/lib/fruit_to_lime/model/deal_status.rb +12 -12
- data/lib/fruit_to_lime/model/note.rb +80 -79
- data/lib/fruit_to_lime/model/organization.rb +203 -203
- data/lib/fruit_to_lime/model/person.rb +151 -151
- data/lib/fruit_to_lime/model/referencetosource.rb +45 -45
- data/lib/fruit_to_lime/model/relation.rb +23 -23
- data/lib/fruit_to_lime/model/rootmodel.rb +342 -338
- data/lib/fruit_to_lime/model/settings.rb +60 -60
- data/lib/fruit_to_lime/model/tag.rb +35 -35
- data/lib/fruit_to_lime/model_helpers.rb +54 -54
- data/lib/fruit_to_lime/phone_helper.rb +74 -74
- data/lib/fruit_to_lime/roo_helper.rb +72 -72
- data/lib/fruit_to_lime/serialize_helper.rb +186 -186
- data/lib/fruit_to_lime/templating.rb +52 -52
- data/spec/address_spec.rb +48 -48
- data/spec/class_settings_spec.rb +37 -37
- data/spec/coworker_spec.rb +94 -94
- data/spec/custom_field_spec.rb +22 -22
- data/spec/deal_spec.rb +101 -101
- data/spec/helpers/csv_helper_spec.rb +29 -29
- data/spec/helpers/email_helper_spec.rb +32 -32
- data/spec/helpers/phone_helper_spec.rb +97 -97
- data/spec/helpers/serialize_helper_spec.rb +249 -249
- data/spec/helpers/xsd_validate_spec.rb +58 -58
- data/spec/note_spec.rb +98 -98
- data/spec/organization_spec.rb +103 -103
- data/spec/person_spec.rb +134 -134
- data/spec/rootmodel_spec.rb +306 -277
- data/spec/templating_spec.rb +11 -11
- data/templates/csv/lib/tomodel.rb +230 -230
- data/templates/csv/spec/exporter_spec.rb +17 -17
- data/templates/csv/spec/sample_data/coworkers.csv +2 -2
- data/templates/csv/spec/sample_data/deals.csv +2 -2
- data/templates/csv/spec/sample_data/organizations.csv +2 -2
- data/templates/csv/spec/sample_data/persons.csv +2 -2
- data/templates/easy/Gemfile +5 -5
- data/templates/easy/Rakefile.rb +7 -7
- data/templates/easy/convert.rb +2 -2
- data/templates/easy/spec/exporter_spec.rb +10 -10
- data/templates/easy/spec/spec_helper.rb +24 -24
- data/templates/excel/lib/tomodel.rb +207 -207
- data/templates/sqlserver/lib/tomodel.rb +79 -79
- metadata +3 -3
data/spec/templating_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
describe 'Templating' do
|
5
|
-
let(:templating) { FruitToLime::Templating.new(File.expand_path("../templates", File.dirname(__FILE__))) }
|
6
|
-
|
7
|
-
describe 'list' do
|
8
|
-
it 'can find some templates' do
|
9
|
-
templating.list().length.should > 0
|
10
|
-
end
|
11
|
-
end
|
1
|
+
require 'fileutils'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
describe 'Templating' do
|
5
|
+
let(:templating) { FruitToLime::Templating.new(File.expand_path("../templates", File.dirname(__FILE__))) }
|
6
|
+
|
7
|
+
describe 'list' do
|
8
|
+
it 'can find some templates' do
|
9
|
+
templating.list().length.should > 0
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
@@ -1,230 +1,230 @@
|
|
1
|
-
require 'fruit_to_lime'
|
2
|
-
|
3
|
-
class Exporter
|
4
|
-
# turns a row from the organization cssv file into
|
5
|
-
# a fruit_to_lime model that is used to generate xml
|
6
|
-
# Uses rootmodel to locate other related stuff such
|
7
|
-
# coworker
|
8
|
-
def to_organization(row, rootmodel)
|
9
|
-
organization = FruitToLime::Organization.new
|
10
|
-
# Integrationid is typically the id in the system that
|
11
|
-
# we are getting the csv from. Must be set to be able
|
12
|
-
# to import the same file more than once without
|
13
|
-
# creating duplicates
|
14
|
-
organization.integration_id = row['id']
|
15
|
-
organization.name = row['name']
|
16
|
-
# Just setting all basic properties to show whats available
|
17
|
-
# Remove or fix...
|
18
|
-
organization.organization_number = 'a number' # needs clean up, should have helpers for that in lib. Swedish format.
|
19
|
-
organization.email = 'email to organizaiton, not the person'
|
20
|
-
organization.web_site = 'www.whatever.com'
|
21
|
-
organization.central_phone_number = '0000' # needs clean up, should have helpers for that in lib. Default swedish format, convert to global format
|
22
|
-
|
23
|
-
# Addresses consists of several parts in Go.
|
24
|
-
# Lots of other systems have the address all in one
|
25
|
-
# line, to be able to match when importing it is
|
26
|
-
# way better to split the addresses
|
27
|
-
organization.with_visit_address do |address|
|
28
|
-
address.street = 'visit street'
|
29
|
-
address.zip_code = 'visit zip'
|
30
|
-
address.city = 'visit city'
|
31
|
-
end
|
32
|
-
|
33
|
-
# Another example of setting address using
|
34
|
-
# helper to split '226 48 LUND' into zip and city
|
35
|
-
organization.with_postal_address do |address|
|
36
|
-
address.street = 'postal street'
|
37
|
-
address.parse_zip_and_address_se '226 48 LUND'
|
38
|
-
end
|
39
|
-
|
40
|
-
# Responsible coworker is set by first locating
|
41
|
-
# it in the root model and then setting a reference
|
42
|
-
# to him/her
|
43
|
-
# We need to be able handle missing coworkers here
|
44
|
-
coworker = rootmodel.find_coworker_by_integration_id row['responsible_id']
|
45
|
-
organization.responsible_coworker = coworker.to_reference
|
46
|
-
|
47
|
-
# Tags are set and defined at the same place
|
48
|
-
# Setting a tag: Imported is useful for the user
|
49
|
-
organization.set_tag("Imported")
|
50
|
-
|
51
|
-
# When imported from web based ERP or similair that
|
52
|
-
# client will continue to use it can be useful to be
|
53
|
-
# able to link from Go to the same record in the ERP
|
54
|
-
# FOr instance Lime links
|
55
|
-
organization.set_custom_value("external_url", "http://something.com?key=#{row['id']}")
|
56
|
-
|
57
|
-
return organization
|
58
|
-
end
|
59
|
-
|
60
|
-
def to_coworker(row)
|
61
|
-
coworker = FruitToLime::Coworker.new
|
62
|
-
coworker.integration_id = row['id']
|
63
|
-
coworker.first_name = row['first_name']
|
64
|
-
coworker.last_name = row['last_name']
|
65
|
-
# Other optional attributes
|
66
|
-
coworker.email = 't@e.com'
|
67
|
-
coworker.direct_phone_number = '+46121212'
|
68
|
-
coworker.mobile_phone_number = '+46324234'
|
69
|
-
coworker.home_phone_number = '+46234234'
|
70
|
-
|
71
|
-
# Tags and custom fields are set the same
|
72
|
-
# way as on organizations
|
73
|
-
|
74
|
-
return coworker
|
75
|
-
end
|
76
|
-
|
77
|
-
def to_person(row, rootmodel)
|
78
|
-
person = FruitToLime::Person.new
|
79
|
-
person.integration_id = row['id']
|
80
|
-
# Note that Go has separate first and last names
|
81
|
-
# Some splitting might be necessary
|
82
|
-
person.first_name = row['first_name']
|
83
|
-
person.last_name = row['last_name']
|
84
|
-
# other optional attributes
|
85
|
-
person.direct_phone_number = '+4611111'
|
86
|
-
person.fax_phone_number = '+4623234234234'
|
87
|
-
person.mobile_phone_number = '+462321212'
|
88
|
-
person.email = 'x@y.com'
|
89
|
-
person.alternative_email = 'y@x.com'
|
90
|
-
person.with_postal_address do |address|
|
91
|
-
address.street = 'postal street'
|
92
|
-
address.parse_zip_and_address_se '226 48 LUND'
|
93
|
-
end
|
94
|
-
|
95
|
-
# Tags and custom fields are set the same
|
96
|
-
# way as on organizations
|
97
|
-
|
98
|
-
# set employer connection
|
99
|
-
employer_id = row['employer_id']
|
100
|
-
employer = rootmodel.find_organization_by_integration_id employer_id
|
101
|
-
employer.add_employee person
|
102
|
-
end
|
103
|
-
|
104
|
-
def to_deal(row, rootmodel)
|
105
|
-
deal = FruitToLime::Deal.new
|
106
|
-
deal.integration_id = row['id']
|
107
|
-
deal.name = row['name']
|
108
|
-
# should be integer, same currency should be used in
|
109
|
-
# the system
|
110
|
-
deal.value = row['value']
|
111
|
-
|
112
|
-
# find stuff connected to deal
|
113
|
-
responsible = rootmodel.find_coworker_by_integration_id row['responsible_id']
|
114
|
-
organization = rootmodel.find_organization_by_integration_id row['customer_id']
|
115
|
-
person = organization.find_employee_by_integration_id row['customer_contact_id']
|
116
|
-
# connect the deal by references
|
117
|
-
deal.responsible_coworker = responsible.to_reference
|
118
|
-
deal.customer = organization.to_reference
|
119
|
-
deal.customer_contact = person.to_reference
|
120
|
-
|
121
|
-
# other optional attributes
|
122
|
-
deal.probability = 50 # should be between 0 - 100
|
123
|
-
deal.order_date = '2014-01-05' # Format ?
|
124
|
-
|
125
|
-
# status, how do we set this ?
|
126
|
-
|
127
|
-
return deal
|
128
|
-
end
|
129
|
-
|
130
|
-
def configure(model)
|
131
|
-
# add custom field to your model here. Custom fields can be
|
132
|
-
# added to organization, deal and person. Valid types are
|
133
|
-
# :String and :Link. If no type is specified :String is used
|
134
|
-
# as default.
|
135
|
-
model.settings.with_organization do |organization|
|
136
|
-
organization.set_custom_field( { :integrationid => 'external_url', :title => 'Link to external system', :type => :Link } )
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def process_rows(file_name)
|
141
|
-
data = File.open(file_name, 'r').read.encode('UTF-8',"ISO-8859-1")
|
142
|
-
rows = FruitToLime::CsvHelper::text_to_hashes(data)
|
143
|
-
rows.each do |row|
|
144
|
-
yield row
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def to_model(coworkers_filename, organization_filename, persons_filename, deals_filename)
|
149
|
-
# A rootmodel is used to represent all entitite/models
|
150
|
-
# that is exported
|
151
|
-
rootmodel = FruitToLime::RootModel.new
|
152
|
-
|
153
|
-
configure rootmodel
|
154
|
-
|
155
|
-
# coworkers
|
156
|
-
# start with these since they are referenced
|
157
|
-
# from everywhere....
|
158
|
-
if coworkers_filename != nil
|
159
|
-
process_rows coworkers_filename do |row|
|
160
|
-
rootmodel.add_coworker(to_coworker(row))
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# organizations
|
165
|
-
if organization_filename != nil
|
166
|
-
process_rows organization_filename do |row|
|
167
|
-
rootmodel.organizations.push(to_organization(row, rootmodel))
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# persons
|
172
|
-
# depends on organizations
|
173
|
-
if persons_filename != nil
|
174
|
-
process_rows persons_filename do |row|
|
175
|
-
# adds it self to the employer
|
176
|
-
to_person(row, rootmodel)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# deals
|
181
|
-
# deals can reference coworkers (responsible), organizations
|
182
|
-
# and persons (contact)
|
183
|
-
if deals_filename != nil
|
184
|
-
process_rows deals_filename do |row|
|
185
|
-
rootmodel.deals.push(to_deal(row, rootmodel))
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
return rootmodel
|
190
|
-
end
|
191
|
-
|
192
|
-
def save_xml(file)
|
193
|
-
File.open(file,'w') do |f|
|
194
|
-
f.write(FruitToLime::SerializeHelper::serialize(to_xml_model))
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
require "thor"
|
200
|
-
require "fileutils"
|
201
|
-
require 'pathname'
|
202
|
-
|
203
|
-
class Cli < Thor
|
204
|
-
desc "to_go", "Generates a Go XML file"
|
205
|
-
method_option :output, :desc => "Path to file where xml will be output", :default => "export.xml", :type => :string
|
206
|
-
method_option :organizations, :desc => "Path to organization csv file", :type => :string
|
207
|
-
method_option :persons, :desc => "Path to persons csv file", :type => :string
|
208
|
-
method_option :coworkers, :desc => "Path to coworkers csv file", :type => :string
|
209
|
-
method_option :deals, :desc => "Path to deals csv file", :type => :string
|
210
|
-
def to_go
|
211
|
-
output = options.output
|
212
|
-
exporter = Exporter.new()
|
213
|
-
model = exporter.to_model(options.coworkers, options.organizations, options.persons, options.deals)
|
214
|
-
error = model.sanity_check
|
215
|
-
if error.empty?
|
216
|
-
validation_errors = model.validate
|
217
|
-
|
218
|
-
if validation_errors.empty?
|
219
|
-
model.serialize_to_file(output)
|
220
|
-
puts "Generated Go XML file: '#{output}'."
|
221
|
-
else
|
222
|
-
puts "Could not generate file due to"
|
223
|
-
puts validation_errors
|
224
|
-
end
|
225
|
-
else
|
226
|
-
puts "Could not generate file due to"
|
227
|
-
puts error
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
1
|
+
require 'fruit_to_lime'
|
2
|
+
|
3
|
+
class Exporter
|
4
|
+
# turns a row from the organization cssv file into
|
5
|
+
# a fruit_to_lime model that is used to generate xml
|
6
|
+
# Uses rootmodel to locate other related stuff such
|
7
|
+
# coworker
|
8
|
+
def to_organization(row, rootmodel)
|
9
|
+
organization = FruitToLime::Organization.new
|
10
|
+
# Integrationid is typically the id in the system that
|
11
|
+
# we are getting the csv from. Must be set to be able
|
12
|
+
# to import the same file more than once without
|
13
|
+
# creating duplicates
|
14
|
+
organization.integration_id = row['id']
|
15
|
+
organization.name = row['name']
|
16
|
+
# Just setting all basic properties to show whats available
|
17
|
+
# Remove or fix...
|
18
|
+
organization.organization_number = 'a number' # needs clean up, should have helpers for that in lib. Swedish format.
|
19
|
+
organization.email = 'email to organizaiton, not the person'
|
20
|
+
organization.web_site = 'www.whatever.com'
|
21
|
+
organization.central_phone_number = '0000' # needs clean up, should have helpers for that in lib. Default swedish format, convert to global format
|
22
|
+
|
23
|
+
# Addresses consists of several parts in Go.
|
24
|
+
# Lots of other systems have the address all in one
|
25
|
+
# line, to be able to match when importing it is
|
26
|
+
# way better to split the addresses
|
27
|
+
organization.with_visit_address do |address|
|
28
|
+
address.street = 'visit street'
|
29
|
+
address.zip_code = 'visit zip'
|
30
|
+
address.city = 'visit city'
|
31
|
+
end
|
32
|
+
|
33
|
+
# Another example of setting address using
|
34
|
+
# helper to split '226 48 LUND' into zip and city
|
35
|
+
organization.with_postal_address do |address|
|
36
|
+
address.street = 'postal street'
|
37
|
+
address.parse_zip_and_address_se '226 48 LUND'
|
38
|
+
end
|
39
|
+
|
40
|
+
# Responsible coworker is set by first locating
|
41
|
+
# it in the root model and then setting a reference
|
42
|
+
# to him/her
|
43
|
+
# We need to be able handle missing coworkers here
|
44
|
+
coworker = rootmodel.find_coworker_by_integration_id row['responsible_id']
|
45
|
+
organization.responsible_coworker = coworker.to_reference
|
46
|
+
|
47
|
+
# Tags are set and defined at the same place
|
48
|
+
# Setting a tag: Imported is useful for the user
|
49
|
+
organization.set_tag("Imported")
|
50
|
+
|
51
|
+
# When imported from web based ERP or similair that
|
52
|
+
# client will continue to use it can be useful to be
|
53
|
+
# able to link from Go to the same record in the ERP
|
54
|
+
# FOr instance Lime links
|
55
|
+
organization.set_custom_value("external_url", "http://something.com?key=#{row['id']}")
|
56
|
+
|
57
|
+
return organization
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_coworker(row)
|
61
|
+
coworker = FruitToLime::Coworker.new
|
62
|
+
coworker.integration_id = row['id']
|
63
|
+
coworker.first_name = row['first_name']
|
64
|
+
coworker.last_name = row['last_name']
|
65
|
+
# Other optional attributes
|
66
|
+
coworker.email = 't@e.com'
|
67
|
+
coworker.direct_phone_number = '+46121212'
|
68
|
+
coworker.mobile_phone_number = '+46324234'
|
69
|
+
coworker.home_phone_number = '+46234234'
|
70
|
+
|
71
|
+
# Tags and custom fields are set the same
|
72
|
+
# way as on organizations
|
73
|
+
|
74
|
+
return coworker
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_person(row, rootmodel)
|
78
|
+
person = FruitToLime::Person.new
|
79
|
+
person.integration_id = row['id']
|
80
|
+
# Note that Go has separate first and last names
|
81
|
+
# Some splitting might be necessary
|
82
|
+
person.first_name = row['first_name']
|
83
|
+
person.last_name = row['last_name']
|
84
|
+
# other optional attributes
|
85
|
+
person.direct_phone_number = '+4611111'
|
86
|
+
person.fax_phone_number = '+4623234234234'
|
87
|
+
person.mobile_phone_number = '+462321212'
|
88
|
+
person.email = 'x@y.com'
|
89
|
+
person.alternative_email = 'y@x.com'
|
90
|
+
person.with_postal_address do |address|
|
91
|
+
address.street = 'postal street'
|
92
|
+
address.parse_zip_and_address_se '226 48 LUND'
|
93
|
+
end
|
94
|
+
|
95
|
+
# Tags and custom fields are set the same
|
96
|
+
# way as on organizations
|
97
|
+
|
98
|
+
# set employer connection
|
99
|
+
employer_id = row['employer_id']
|
100
|
+
employer = rootmodel.find_organization_by_integration_id employer_id
|
101
|
+
employer.add_employee person
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_deal(row, rootmodel)
|
105
|
+
deal = FruitToLime::Deal.new
|
106
|
+
deal.integration_id = row['id']
|
107
|
+
deal.name = row['name']
|
108
|
+
# should be integer, same currency should be used in
|
109
|
+
# the system
|
110
|
+
deal.value = row['value']
|
111
|
+
|
112
|
+
# find stuff connected to deal
|
113
|
+
responsible = rootmodel.find_coworker_by_integration_id row['responsible_id']
|
114
|
+
organization = rootmodel.find_organization_by_integration_id row['customer_id']
|
115
|
+
person = organization.find_employee_by_integration_id row['customer_contact_id']
|
116
|
+
# connect the deal by references
|
117
|
+
deal.responsible_coworker = responsible.to_reference
|
118
|
+
deal.customer = organization.to_reference
|
119
|
+
deal.customer_contact = person.to_reference
|
120
|
+
|
121
|
+
# other optional attributes
|
122
|
+
deal.probability = 50 # should be between 0 - 100
|
123
|
+
deal.order_date = '2014-01-05' # Format ?
|
124
|
+
|
125
|
+
# status, how do we set this ?
|
126
|
+
|
127
|
+
return deal
|
128
|
+
end
|
129
|
+
|
130
|
+
def configure(model)
|
131
|
+
# add custom field to your model here. Custom fields can be
|
132
|
+
# added to organization, deal and person. Valid types are
|
133
|
+
# :String and :Link. If no type is specified :String is used
|
134
|
+
# as default.
|
135
|
+
model.settings.with_organization do |organization|
|
136
|
+
organization.set_custom_field( { :integrationid => 'external_url', :title => 'Link to external system', :type => :Link } )
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def process_rows(file_name)
|
141
|
+
data = File.open(file_name, 'r').read.encode('UTF-8',"ISO-8859-1")
|
142
|
+
rows = FruitToLime::CsvHelper::text_to_hashes(data)
|
143
|
+
rows.each do |row|
|
144
|
+
yield row
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def to_model(coworkers_filename, organization_filename, persons_filename, deals_filename)
|
149
|
+
# A rootmodel is used to represent all entitite/models
|
150
|
+
# that is exported
|
151
|
+
rootmodel = FruitToLime::RootModel.new
|
152
|
+
|
153
|
+
configure rootmodel
|
154
|
+
|
155
|
+
# coworkers
|
156
|
+
# start with these since they are referenced
|
157
|
+
# from everywhere....
|
158
|
+
if coworkers_filename != nil
|
159
|
+
process_rows coworkers_filename do |row|
|
160
|
+
rootmodel.add_coworker(to_coworker(row))
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# organizations
|
165
|
+
if organization_filename != nil
|
166
|
+
process_rows organization_filename do |row|
|
167
|
+
rootmodel.organizations.push(to_organization(row, rootmodel))
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# persons
|
172
|
+
# depends on organizations
|
173
|
+
if persons_filename != nil
|
174
|
+
process_rows persons_filename do |row|
|
175
|
+
# adds it self to the employer
|
176
|
+
to_person(row, rootmodel)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# deals
|
181
|
+
# deals can reference coworkers (responsible), organizations
|
182
|
+
# and persons (contact)
|
183
|
+
if deals_filename != nil
|
184
|
+
process_rows deals_filename do |row|
|
185
|
+
rootmodel.deals.push(to_deal(row, rootmodel))
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
return rootmodel
|
190
|
+
end
|
191
|
+
|
192
|
+
def save_xml(file)
|
193
|
+
File.open(file,'w') do |f|
|
194
|
+
f.write(FruitToLime::SerializeHelper::serialize(to_xml_model))
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
require "thor"
|
200
|
+
require "fileutils"
|
201
|
+
require 'pathname'
|
202
|
+
|
203
|
+
class Cli < Thor
|
204
|
+
desc "to_go", "Generates a Go XML file"
|
205
|
+
method_option :output, :desc => "Path to file where xml will be output", :default => "export.xml", :type => :string
|
206
|
+
method_option :organizations, :desc => "Path to organization csv file", :type => :string
|
207
|
+
method_option :persons, :desc => "Path to persons csv file", :type => :string
|
208
|
+
method_option :coworkers, :desc => "Path to coworkers csv file", :type => :string
|
209
|
+
method_option :deals, :desc => "Path to deals csv file", :type => :string
|
210
|
+
def to_go
|
211
|
+
output = options.output
|
212
|
+
exporter = Exporter.new()
|
213
|
+
model = exporter.to_model(options.coworkers, options.organizations, options.persons, options.deals)
|
214
|
+
error = model.sanity_check
|
215
|
+
if error.empty?
|
216
|
+
validation_errors = model.validate
|
217
|
+
|
218
|
+
if validation_errors.empty?
|
219
|
+
model.serialize_to_file(output)
|
220
|
+
puts "Generated Go XML file: '#{output}'."
|
221
|
+
else
|
222
|
+
puts "Could not generate file due to"
|
223
|
+
puts validation_errors
|
224
|
+
end
|
225
|
+
else
|
226
|
+
puts "Could not generate file due to"
|
227
|
+
puts error
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|