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.
- 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
@@ -1,203 +1,203 @@
|
|
1
|
-
module FruitToLime
|
2
|
-
class OrganizationReference
|
3
|
-
include SerializeHelper
|
4
|
-
attr_accessor :id, :integration_id, :heading
|
5
|
-
def serialize_variables
|
6
|
-
[ :id, :integration_id, :heading ].map { |prop| {
|
7
|
-
:id => prop, :type => :string
|
8
|
-
}
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(opt = nil)
|
13
|
-
if opt != nil
|
14
|
-
serialize_variables.each do |var|
|
15
|
-
value = opt[var[:id]]
|
16
|
-
instance_variable_set("@" + var[:id].to_s, value) if value != nil
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_s
|
22
|
-
return "(#{id}, #{integration_id}, #{heading})"
|
23
|
-
end
|
24
|
-
|
25
|
-
def empty?
|
26
|
-
return !@integration_id && !@id && !@heading
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.from_organization(organization)
|
30
|
-
if organization.nil?
|
31
|
-
return nil
|
32
|
-
elsif organization.is_a?(Organization)
|
33
|
-
return organization.to_reference
|
34
|
-
elsif organization.is_a?(OrganizationReference)
|
35
|
-
return organization
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class Organization
|
41
|
-
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
42
|
-
|
43
|
-
attr_accessor :id, :integration_id, :name, :organization_number, :email, :web_site,
|
44
|
-
:postal_address, :visit_address, :central_phone_number, :source_data
|
45
|
-
|
46
|
-
attr_reader :employees, :responsible_coworker, :relation
|
47
|
-
# you add custom values by using {#set_custom_value}
|
48
|
-
attr_reader :custom_values
|
49
|
-
|
50
|
-
def initialize(opt = nil)
|
51
|
-
if !opt.nil?
|
52
|
-
serialize_variables.each do |myattr|
|
53
|
-
val = opt[myattr[:id]]
|
54
|
-
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
@relation = Relation::NoRelation if @relation.nil?
|
59
|
-
end
|
60
|
-
|
61
|
-
def to_reference()
|
62
|
-
reference = OrganizationReference.new
|
63
|
-
reference.id = @id
|
64
|
-
reference.integration_id = @integration_id
|
65
|
-
reference.heading = @name
|
66
|
-
return reference
|
67
|
-
end
|
68
|
-
|
69
|
-
def ==(that)
|
70
|
-
if that.nil?
|
71
|
-
return false
|
72
|
-
end
|
73
|
-
|
74
|
-
if that.is_a? Organization
|
75
|
-
return @integration_id == that.integration_id
|
76
|
-
end
|
77
|
-
|
78
|
-
return false
|
79
|
-
end
|
80
|
-
|
81
|
-
# @example Set city of postal address to 'Lund'
|
82
|
-
# o.with_postal_address do |addr|
|
83
|
-
# addr.city = "Lund"
|
84
|
-
# end
|
85
|
-
# @see Address address
|
86
|
-
def with_postal_address
|
87
|
-
@postal_address = Address.new if @postal_address == nil
|
88
|
-
yield @postal_address
|
89
|
-
end
|
90
|
-
|
91
|
-
# @example Set city of visit address to 'Lund'
|
92
|
-
# o.with_visit_address do |addr|
|
93
|
-
# addr.city = "Lund"
|
94
|
-
# end
|
95
|
-
# @see Address address
|
96
|
-
def with_visit_address
|
97
|
-
@visit_address = Address.new if @visit_address == nil
|
98
|
-
yield @visit_address
|
99
|
-
end
|
100
|
-
|
101
|
-
# @example Set the source to par id 4653
|
102
|
-
# o.with_source do |source|
|
103
|
-
# source.par_se('4653')
|
104
|
-
# end
|
105
|
-
# @see ReferenceToSource source
|
106
|
-
def with_source
|
107
|
-
@source = ReferenceToSource.new if @source == nil
|
108
|
-
yield @source
|
109
|
-
end
|
110
|
-
|
111
|
-
# @example Add an employee and then add additional info to that employee
|
112
|
-
# employee = o.add_employee({
|
113
|
-
# :integration_id => "79654",
|
114
|
-
# :first_name => "Peter",
|
115
|
-
# :last_name => "Wilhelmsson"
|
116
|
-
# })
|
117
|
-
# employee.direct_phone_number = '+234234234'
|
118
|
-
# employee.currently_employed = true
|
119
|
-
# @see Person employee
|
120
|
-
def add_employee(val)
|
121
|
-
@employees = [] if @employees == nil
|
122
|
-
person = if val.is_a? Person then val else Person.new(val) end
|
123
|
-
@employees.push(person)
|
124
|
-
person
|
125
|
-
end
|
126
|
-
|
127
|
-
def responsible_coworker=(coworker)
|
128
|
-
@responsible_coworker = CoworkerReference.from_coworker(coworker)
|
129
|
-
end
|
130
|
-
|
131
|
-
# Sets the organization's relation to the specified value. The
|
132
|
-
# relation must be a valid value from the Relation module
|
133
|
-
# otherwise an InvalidRelationError error will be thrown.
|
134
|
-
def relation=(relation)
|
135
|
-
if relation == Relation::NoRelation || relation == Relation::WorkingOnIt ||
|
136
|
-
relation == Relation::IsACustomer || relation == Relation::WasACustomer || relation == Relation::BeenInTouch
|
137
|
-
@relation = relation
|
138
|
-
else
|
139
|
-
raise InvalidRelationError
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def find_employee_by_integration_id(integration_id)
|
144
|
-
return nil if @employees.nil?
|
145
|
-
return @employees.find do |e|
|
146
|
-
e.integration_id == integration_id
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def serialize_variables
|
151
|
-
[
|
152
|
-
{ :id => :id, :type => :string },
|
153
|
-
{ :id => :integration_id, :type => :string },
|
154
|
-
{ :id => :source, :type => :source_ref },
|
155
|
-
{ :id => :name, :type => :string },
|
156
|
-
{ :id => :organization_number, :type => :string },
|
157
|
-
{ :id => :postal_address, :type => :address },
|
158
|
-
{ :id => :visit_address, :type => :address },
|
159
|
-
{ :id => :central_phone_number, :type => :string },
|
160
|
-
{ :id => :email, :type => :string },
|
161
|
-
{ :id => :web_site, :type => :string },
|
162
|
-
{ :id => :employees, :type => :persons },
|
163
|
-
{ :id => :custom_values, :type => :custom_values },
|
164
|
-
{ :id => :tags, :type => :tags },
|
165
|
-
{ :id => :responsible_coworker, :type => :coworker_reference},
|
166
|
-
{ :id => :relation, :type => :string }
|
167
|
-
]
|
168
|
-
end
|
169
|
-
|
170
|
-
def serialize_name
|
171
|
-
"Organization"
|
172
|
-
end
|
173
|
-
|
174
|
-
def to_s
|
175
|
-
return "#{name}"
|
176
|
-
end
|
177
|
-
|
178
|
-
def validate
|
179
|
-
error = String.new
|
180
|
-
|
181
|
-
if @name.nil? || @name.empty?
|
182
|
-
error = "A name is required for organization.\n#{serialize()}"
|
183
|
-
end
|
184
|
-
|
185
|
-
if !@source.nil?
|
186
|
-
if @source.id.nil? || @source.id == ""
|
187
|
-
error = "#{error}\nReference to source must have an id"
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
if @employees != nil
|
192
|
-
@employees.each do |person|
|
193
|
-
validation_message = person.validate()
|
194
|
-
if !validation_message.empty?
|
195
|
-
error = "#{error}\n#{validation_message}"
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
return error
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
1
|
+
module FruitToLime
|
2
|
+
class OrganizationReference
|
3
|
+
include SerializeHelper
|
4
|
+
attr_accessor :id, :integration_id, :heading
|
5
|
+
def serialize_variables
|
6
|
+
[ :id, :integration_id, :heading ].map { |prop| {
|
7
|
+
:id => prop, :type => :string
|
8
|
+
}
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(opt = nil)
|
13
|
+
if opt != nil
|
14
|
+
serialize_variables.each do |var|
|
15
|
+
value = opt[var[:id]]
|
16
|
+
instance_variable_set("@" + var[:id].to_s, value) if value != nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
return "(#{id}, #{integration_id}, #{heading})"
|
23
|
+
end
|
24
|
+
|
25
|
+
def empty?
|
26
|
+
return !@integration_id && !@id && !@heading
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.from_organization(organization)
|
30
|
+
if organization.nil?
|
31
|
+
return nil
|
32
|
+
elsif organization.is_a?(Organization)
|
33
|
+
return organization.to_reference
|
34
|
+
elsif organization.is_a?(OrganizationReference)
|
35
|
+
return organization
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Organization
|
41
|
+
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
42
|
+
|
43
|
+
attr_accessor :id, :integration_id, :name, :organization_number, :email, :web_site,
|
44
|
+
:postal_address, :visit_address, :central_phone_number, :source_data
|
45
|
+
|
46
|
+
attr_reader :employees, :responsible_coworker, :relation
|
47
|
+
# you add custom values by using {#set_custom_value}
|
48
|
+
attr_reader :custom_values
|
49
|
+
|
50
|
+
def initialize(opt = nil)
|
51
|
+
if !opt.nil?
|
52
|
+
serialize_variables.each do |myattr|
|
53
|
+
val = opt[myattr[:id]]
|
54
|
+
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
@relation = Relation::NoRelation if @relation.nil?
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_reference()
|
62
|
+
reference = OrganizationReference.new
|
63
|
+
reference.id = @id
|
64
|
+
reference.integration_id = @integration_id
|
65
|
+
reference.heading = @name
|
66
|
+
return reference
|
67
|
+
end
|
68
|
+
|
69
|
+
def ==(that)
|
70
|
+
if that.nil?
|
71
|
+
return false
|
72
|
+
end
|
73
|
+
|
74
|
+
if that.is_a? Organization
|
75
|
+
return @integration_id == that.integration_id
|
76
|
+
end
|
77
|
+
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
|
81
|
+
# @example Set city of postal address to 'Lund'
|
82
|
+
# o.with_postal_address do |addr|
|
83
|
+
# addr.city = "Lund"
|
84
|
+
# end
|
85
|
+
# @see Address address
|
86
|
+
def with_postal_address
|
87
|
+
@postal_address = Address.new if @postal_address == nil
|
88
|
+
yield @postal_address
|
89
|
+
end
|
90
|
+
|
91
|
+
# @example Set city of visit address to 'Lund'
|
92
|
+
# o.with_visit_address do |addr|
|
93
|
+
# addr.city = "Lund"
|
94
|
+
# end
|
95
|
+
# @see Address address
|
96
|
+
def with_visit_address
|
97
|
+
@visit_address = Address.new if @visit_address == nil
|
98
|
+
yield @visit_address
|
99
|
+
end
|
100
|
+
|
101
|
+
# @example Set the source to par id 4653
|
102
|
+
# o.with_source do |source|
|
103
|
+
# source.par_se('4653')
|
104
|
+
# end
|
105
|
+
# @see ReferenceToSource source
|
106
|
+
def with_source
|
107
|
+
@source = ReferenceToSource.new if @source == nil
|
108
|
+
yield @source
|
109
|
+
end
|
110
|
+
|
111
|
+
# @example Add an employee and then add additional info to that employee
|
112
|
+
# employee = o.add_employee({
|
113
|
+
# :integration_id => "79654",
|
114
|
+
# :first_name => "Peter",
|
115
|
+
# :last_name => "Wilhelmsson"
|
116
|
+
# })
|
117
|
+
# employee.direct_phone_number = '+234234234'
|
118
|
+
# employee.currently_employed = true
|
119
|
+
# @see Person employee
|
120
|
+
def add_employee(val)
|
121
|
+
@employees = [] if @employees == nil
|
122
|
+
person = if val.is_a? Person then val else Person.new(val) end
|
123
|
+
@employees.push(person)
|
124
|
+
person
|
125
|
+
end
|
126
|
+
|
127
|
+
def responsible_coworker=(coworker)
|
128
|
+
@responsible_coworker = CoworkerReference.from_coworker(coworker)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Sets the organization's relation to the specified value. The
|
132
|
+
# relation must be a valid value from the Relation module
|
133
|
+
# otherwise an InvalidRelationError error will be thrown.
|
134
|
+
def relation=(relation)
|
135
|
+
if relation == Relation::NoRelation || relation == Relation::WorkingOnIt ||
|
136
|
+
relation == Relation::IsACustomer || relation == Relation::WasACustomer || relation == Relation::BeenInTouch
|
137
|
+
@relation = relation
|
138
|
+
else
|
139
|
+
raise InvalidRelationError
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def find_employee_by_integration_id(integration_id)
|
144
|
+
return nil if @employees.nil?
|
145
|
+
return @employees.find do |e|
|
146
|
+
e.integration_id == integration_id
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def serialize_variables
|
151
|
+
[
|
152
|
+
{ :id => :id, :type => :string },
|
153
|
+
{ :id => :integration_id, :type => :string },
|
154
|
+
{ :id => :source, :type => :source_ref },
|
155
|
+
{ :id => :name, :type => :string },
|
156
|
+
{ :id => :organization_number, :type => :string },
|
157
|
+
{ :id => :postal_address, :type => :address },
|
158
|
+
{ :id => :visit_address, :type => :address },
|
159
|
+
{ :id => :central_phone_number, :type => :string },
|
160
|
+
{ :id => :email, :type => :string },
|
161
|
+
{ :id => :web_site, :type => :string },
|
162
|
+
{ :id => :employees, :type => :persons },
|
163
|
+
{ :id => :custom_values, :type => :custom_values },
|
164
|
+
{ :id => :tags, :type => :tags },
|
165
|
+
{ :id => :responsible_coworker, :type => :coworker_reference},
|
166
|
+
{ :id => :relation, :type => :string }
|
167
|
+
]
|
168
|
+
end
|
169
|
+
|
170
|
+
def serialize_name
|
171
|
+
"Organization"
|
172
|
+
end
|
173
|
+
|
174
|
+
def to_s
|
175
|
+
return "#{name}"
|
176
|
+
end
|
177
|
+
|
178
|
+
def validate
|
179
|
+
error = String.new
|
180
|
+
|
181
|
+
if @name.nil? || @name.empty?
|
182
|
+
error = "A name is required for organization.\n#{serialize()}"
|
183
|
+
end
|
184
|
+
|
185
|
+
if !@source.nil?
|
186
|
+
if @source.id.nil? || @source.id == ""
|
187
|
+
error = "#{error}\nReference to source must have an id"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
if @employees != nil
|
192
|
+
@employees.each do |person|
|
193
|
+
validation_message = person.validate()
|
194
|
+
if !validation_message.empty?
|
195
|
+
error = "#{error}\n#{validation_message}"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
return error
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -1,151 +1,151 @@
|
|
1
|
-
module FruitToLime
|
2
|
-
class PersonReference
|
3
|
-
include SerializeHelper
|
4
|
-
attr_accessor :id, :integration_id
|
5
|
-
def serialize_variables
|
6
|
-
[ :id, :integration_id ].map { |prop| {:id=>prop,:type=>:string} }
|
7
|
-
end
|
8
|
-
|
9
|
-
def initalize()
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
return "(#{id}, #{integration_id})"
|
14
|
-
end
|
15
|
-
|
16
|
-
def empty?
|
17
|
-
return !@integration_id && !@id
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.from_person(person)
|
21
|
-
if person.nil?
|
22
|
-
return nil
|
23
|
-
elsif person.is_a?(Person)
|
24
|
-
return person.to_reference
|
25
|
-
elsif person.is_a?(PersonReference)
|
26
|
-
return person
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class Person < PersonReference
|
32
|
-
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
33
|
-
attr_accessor :first_name, :last_name,
|
34
|
-
:direct_phone_number, :fax_phone_number, :mobile_phone_number, :home_phone_number,
|
35
|
-
:position, :email, :alternative_email, :postal_address, :currently_employed
|
36
|
-
|
37
|
-
# you add custom values by using {#set_custom_value}
|
38
|
-
attr_reader :custom_values, :organization
|
39
|
-
|
40
|
-
def initialize(opt = nil)
|
41
|
-
@currently_employed = true
|
42
|
-
if opt != nil
|
43
|
-
serialize_variables.each do |myattr|
|
44
|
-
val = opt[myattr[:id]]
|
45
|
-
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def organization=(org)
|
51
|
-
@organization = OrganizationReference.from_organization(org)
|
52
|
-
end
|
53
|
-
|
54
|
-
# @example Set city of postal address to 'Lund'
|
55
|
-
# p.with_postal_address do |addr|
|
56
|
-
# addr.city = "Lund"
|
57
|
-
# end
|
58
|
-
# @see Address address
|
59
|
-
def with_postal_address
|
60
|
-
@postal_address = Address.new if @postal_address == nil
|
61
|
-
yield @postal_address
|
62
|
-
end
|
63
|
-
|
64
|
-
# @example Set the source to par id 4653
|
65
|
-
# p.with_source do |source|
|
66
|
-
# source.par_se('4653')
|
67
|
-
# end
|
68
|
-
# @see ReferenceToSource source
|
69
|
-
def with_source
|
70
|
-
@source = ReferenceToSource.new if @source == nil
|
71
|
-
yield @source
|
72
|
-
end
|
73
|
-
|
74
|
-
def tags
|
75
|
-
@tags
|
76
|
-
end
|
77
|
-
|
78
|
-
def serialize_name
|
79
|
-
"Person"
|
80
|
-
end
|
81
|
-
|
82
|
-
def serialize_variables
|
83
|
-
[
|
84
|
-
{:id => :id, :type => :string},
|
85
|
-
{:id => :integration_id, :type => :string},
|
86
|
-
{:id => :source, :type => :source_ref},
|
87
|
-
{:id => :first_name, :type => :string},
|
88
|
-
{:id => :last_name, :type => :string},
|
89
|
-
|
90
|
-
{:id => :direct_phone_number, :type => :string},
|
91
|
-
{:id => :fax_phone_number, :type => :string},
|
92
|
-
{:id => :mobile_phone_number, :type => :string},
|
93
|
-
{:id => :home_phone_number, :type => :string},
|
94
|
-
|
95
|
-
{:id => :position, :type => :string},
|
96
|
-
|
97
|
-
{:id => :tags, :type => :tags},
|
98
|
-
|
99
|
-
{:id => :email, :type => :string},
|
100
|
-
{:id => :alternative_email, :type => :string},
|
101
|
-
|
102
|
-
{:id => :postal_address, :type => :address},
|
103
|
-
{:id => :custom_values, :type => :custom_values},
|
104
|
-
{:id => :currently_employed, :type => :bool},
|
105
|
-
{:id => :organization, :type => :organization_reference},
|
106
|
-
|
107
|
-
]
|
108
|
-
end
|
109
|
-
|
110
|
-
def to_reference()
|
111
|
-
reference = PersonReference.new
|
112
|
-
reference.id = @id
|
113
|
-
reference.integration_id = @integration_id
|
114
|
-
return reference
|
115
|
-
end
|
116
|
-
|
117
|
-
def get_import_rows
|
118
|
-
(serialize_variables + [ { :id => :organization, :type => :organization_reference } ]).map do |p|
|
119
|
-
map_to_row p
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def to_s
|
124
|
-
return "#{first_name} #{last_name}"
|
125
|
-
end
|
126
|
-
|
127
|
-
def validate
|
128
|
-
error = String.new
|
129
|
-
|
130
|
-
if (@first_name.nil? || @first_name.empty?) &&
|
131
|
-
(@last_name.nil? || @last_name.empty?)
|
132
|
-
error = "A firstname or lastname is required for person.\n#{serialize()}"
|
133
|
-
end
|
134
|
-
|
135
|
-
return error
|
136
|
-
end
|
137
|
-
|
138
|
-
def parse_name_to_firstname_lastname_se(name, when_missing = '')
|
139
|
-
if name.nil? or name.empty?
|
140
|
-
@first_name = when_missing
|
141
|
-
return
|
142
|
-
end
|
143
|
-
|
144
|
-
splitted = name.split(' ')
|
145
|
-
@first_name = splitted[0]
|
146
|
-
if splitted.length > 1
|
147
|
-
@last_name = splitted.drop(1).join(' ')
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
1
|
+
module FruitToLime
|
2
|
+
class PersonReference
|
3
|
+
include SerializeHelper
|
4
|
+
attr_accessor :id, :integration_id
|
5
|
+
def serialize_variables
|
6
|
+
[ :id, :integration_id ].map { |prop| {:id=>prop,:type=>:string} }
|
7
|
+
end
|
8
|
+
|
9
|
+
def initalize()
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
return "(#{id}, #{integration_id})"
|
14
|
+
end
|
15
|
+
|
16
|
+
def empty?
|
17
|
+
return !@integration_id && !@id
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_person(person)
|
21
|
+
if person.nil?
|
22
|
+
return nil
|
23
|
+
elsif person.is_a?(Person)
|
24
|
+
return person.to_reference
|
25
|
+
elsif person.is_a?(PersonReference)
|
26
|
+
return person
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Person < PersonReference
|
32
|
+
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
33
|
+
attr_accessor :first_name, :last_name,
|
34
|
+
:direct_phone_number, :fax_phone_number, :mobile_phone_number, :home_phone_number,
|
35
|
+
:position, :email, :alternative_email, :postal_address, :currently_employed
|
36
|
+
|
37
|
+
# you add custom values by using {#set_custom_value}
|
38
|
+
attr_reader :custom_values, :organization
|
39
|
+
|
40
|
+
def initialize(opt = nil)
|
41
|
+
@currently_employed = true
|
42
|
+
if opt != nil
|
43
|
+
serialize_variables.each do |myattr|
|
44
|
+
val = opt[myattr[:id]]
|
45
|
+
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def organization=(org)
|
51
|
+
@organization = OrganizationReference.from_organization(org)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @example Set city of postal address to 'Lund'
|
55
|
+
# p.with_postal_address do |addr|
|
56
|
+
# addr.city = "Lund"
|
57
|
+
# end
|
58
|
+
# @see Address address
|
59
|
+
def with_postal_address
|
60
|
+
@postal_address = Address.new if @postal_address == nil
|
61
|
+
yield @postal_address
|
62
|
+
end
|
63
|
+
|
64
|
+
# @example Set the source to par id 4653
|
65
|
+
# p.with_source do |source|
|
66
|
+
# source.par_se('4653')
|
67
|
+
# end
|
68
|
+
# @see ReferenceToSource source
|
69
|
+
def with_source
|
70
|
+
@source = ReferenceToSource.new if @source == nil
|
71
|
+
yield @source
|
72
|
+
end
|
73
|
+
|
74
|
+
def tags
|
75
|
+
@tags
|
76
|
+
end
|
77
|
+
|
78
|
+
def serialize_name
|
79
|
+
"Person"
|
80
|
+
end
|
81
|
+
|
82
|
+
def serialize_variables
|
83
|
+
[
|
84
|
+
{:id => :id, :type => :string},
|
85
|
+
{:id => :integration_id, :type => :string},
|
86
|
+
{:id => :source, :type => :source_ref},
|
87
|
+
{:id => :first_name, :type => :string},
|
88
|
+
{:id => :last_name, :type => :string},
|
89
|
+
|
90
|
+
{:id => :direct_phone_number, :type => :string},
|
91
|
+
{:id => :fax_phone_number, :type => :string},
|
92
|
+
{:id => :mobile_phone_number, :type => :string},
|
93
|
+
{:id => :home_phone_number, :type => :string},
|
94
|
+
|
95
|
+
{:id => :position, :type => :string},
|
96
|
+
|
97
|
+
{:id => :tags, :type => :tags},
|
98
|
+
|
99
|
+
{:id => :email, :type => :string},
|
100
|
+
{:id => :alternative_email, :type => :string},
|
101
|
+
|
102
|
+
{:id => :postal_address, :type => :address},
|
103
|
+
{:id => :custom_values, :type => :custom_values},
|
104
|
+
{:id => :currently_employed, :type => :bool},
|
105
|
+
{:id => :organization, :type => :organization_reference},
|
106
|
+
|
107
|
+
]
|
108
|
+
end
|
109
|
+
|
110
|
+
def to_reference()
|
111
|
+
reference = PersonReference.new
|
112
|
+
reference.id = @id
|
113
|
+
reference.integration_id = @integration_id
|
114
|
+
return reference
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_import_rows
|
118
|
+
(serialize_variables + [ { :id => :organization, :type => :organization_reference } ]).map do |p|
|
119
|
+
map_to_row p
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_s
|
124
|
+
return "#{first_name} #{last_name}"
|
125
|
+
end
|
126
|
+
|
127
|
+
def validate
|
128
|
+
error = String.new
|
129
|
+
|
130
|
+
if (@first_name.nil? || @first_name.empty?) &&
|
131
|
+
(@last_name.nil? || @last_name.empty?)
|
132
|
+
error = "A firstname or lastname is required for person.\n#{serialize()}"
|
133
|
+
end
|
134
|
+
|
135
|
+
return error
|
136
|
+
end
|
137
|
+
|
138
|
+
def parse_name_to_firstname_lastname_se(name, when_missing = '')
|
139
|
+
if name.nil? or name.empty?
|
140
|
+
@first_name = when_missing
|
141
|
+
return
|
142
|
+
end
|
143
|
+
|
144
|
+
splitted = name.split(' ')
|
145
|
+
@first_name = splitted[0]
|
146
|
+
if splitted.length > 1
|
147
|
+
@last_name = splitted.drop(1).join(' ')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|