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.
- data/bin/fruit_to_lime +24 -24
- data/lib/fruit_to_lime/email_helper.rb +10 -0
- data/lib/fruit_to_lime/errors.rb +4 -1
- data/lib/fruit_to_lime/excel_helper.rb +10 -0
- data/lib/fruit_to_lime/global_phone.json +6571 -0
- data/lib/fruit_to_lime/model/class_settings.rb +7 -4
- data/lib/fruit_to_lime/model/coworker.rb +2 -2
- data/lib/fruit_to_lime/model/coworker_reference.rb +10 -0
- data/lib/fruit_to_lime/model/deal.rb +12 -3
- data/lib/fruit_to_lime/model/note.rb +42 -1
- data/lib/fruit_to_lime/model/organization.rb +29 -7
- data/lib/fruit_to_lime/model/person.rb +26 -9
- data/lib/fruit_to_lime/model/rootmodel.rb +145 -9
- data/lib/fruit_to_lime/phone_helper.rb +74 -0
- data/lib/fruit_to_lime.rb +4 -1
- data/spec/class_settings_spec.rb +23 -3
- data/spec/deal_spec.rb +22 -12
- data/spec/helpers/email_helper_spec.rb +32 -0
- data/spec/helpers/phone_helper_spec.rb +97 -0
- data/spec/helpers/roo_helper_spec.rb +10 -10
- data/spec/note_spec.rb +55 -0
- data/spec/organization_spec.rb +57 -0
- data/spec/person_spec.rb +15 -6
- data/spec/rootmodel_spec.rb +133 -7
- data/spec/spec_helper.rb +24 -24
- data/templates/csv/Gemfile +5 -5
- data/templates/csv/Rakefile.rb +7 -7
- data/templates/csv/convert.rb +2 -2
- data/templates/csv/spec/spec_helper.rb +24 -24
- data/templates/excel/Gemfile +6 -6
- data/templates/excel/Rakefile.rb +7 -7
- data/templates/excel/convert.rb +2 -2
- data/templates/excel/lib/tomodel.rb +167 -29
- data/templates/excel/spec/spec_helper.rb +20 -20
- data/templates/excel/spec/tomodel_spec.rb +18 -18
- data/templates/excel/template.xlsx +0 -0
- data/templates/sqlserver/Gemfile +6 -6
- data/templates/sqlserver/Rakefile.rb +7 -7
- data/templates/sqlserver/convert.rb +2 -2
- data/templates/sqlserver/spec/spec_helper.rb +20 -20
- data/templates/sqlserver/spec/tomodel_spec.rb +9 -9
- metadata +47 -2
@@ -23,7 +23,7 @@ module FruitToLime
|
|
23
23
|
|
24
24
|
# Set custom field. If there is already an existing custom field, then it is overwritten.
|
25
25
|
def set_custom_field(obj)
|
26
|
-
@custom_fields = [] if @custom_fields==nil
|
26
|
+
@custom_fields = [] if @custom_fields == nil
|
27
27
|
|
28
28
|
if obj.is_a?(CustomField)
|
29
29
|
field = obj
|
@@ -31,7 +31,11 @@ module FruitToLime
|
|
31
31
|
field = CustomField.new(obj)
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
if field.integration_id == "" && field.id == ""
|
35
|
+
raise InvalidCustomFieldError, "Custom field must have either id or integration_id"
|
36
|
+
end
|
37
|
+
|
38
|
+
index = @custom_fields.find_index do |custom_field|
|
35
39
|
custom_field.same_as?(field)
|
36
40
|
end
|
37
41
|
if index
|
@@ -42,6 +46,5 @@ module FruitToLime
|
|
42
46
|
|
43
47
|
return field
|
44
48
|
end
|
45
|
-
|
46
49
|
end
|
47
|
-
end
|
50
|
+
end
|
@@ -16,7 +16,7 @@ module FruitToLime
|
|
16
16
|
|
17
17
|
def serialize_variables
|
18
18
|
[
|
19
|
-
:id, :integration_id, :email, :first_name, :last_name,
|
19
|
+
:id, :integration_id, :email, :first_name, :last_name,
|
20
20
|
:direct_phone_number, :mobile_phone_number, :home_phone_number
|
21
21
|
].map {|p| { :id => p, :type => :string } }
|
22
22
|
end
|
@@ -54,7 +54,7 @@ module FruitToLime
|
|
54
54
|
|
55
55
|
splitted = name.split(' ')
|
56
56
|
@first_name = splitted[0]
|
57
|
-
if splitted.length > 1
|
57
|
+
if splitted.length > 1
|
58
58
|
@last_name = splitted.drop(1).join(' ')
|
59
59
|
end
|
60
60
|
end
|
@@ -19,5 +19,15 @@ module FruitToLime
|
|
19
19
|
def serialize_name
|
20
20
|
"CoworkerReference"
|
21
21
|
end
|
22
|
+
|
23
|
+
def self.from_coworker(coworker)
|
24
|
+
if coworker.nil?
|
25
|
+
return nil
|
26
|
+
elsif coworker.is_a?(Coworker)
|
27
|
+
return coworker.to_reference
|
28
|
+
elsif coworker.is_a?(CoworkerReference)
|
29
|
+
return coworker
|
30
|
+
end
|
31
|
+
end
|
22
32
|
end
|
23
33
|
end
|
@@ -3,10 +3,10 @@ module FruitToLime
|
|
3
3
|
class Deal
|
4
4
|
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
5
5
|
|
6
|
-
attr_accessor :id, :integration_id, :name, :description, :probability, :value, :order_date,
|
6
|
+
attr_accessor :id, :integration_id, :name, :description, :probability, :value, :order_date,
|
7
7
|
:responsible_coworker, :customer_contact, :status
|
8
8
|
# you add custom values by using {#set_custom_value}
|
9
|
-
attr_reader :custom_values
|
9
|
+
attr_reader :custom_values, :customer
|
10
10
|
|
11
11
|
def serialize_variables
|
12
12
|
[ :id, :integration_id, :name, :description, :probability, :value, :order_date ].map {
|
@@ -29,7 +29,13 @@ module FruitToLime
|
|
29
29
|
"Deal"
|
30
30
|
end
|
31
31
|
|
32
|
-
def initialize()
|
32
|
+
def initialize(opt = nil)
|
33
|
+
if !opt.nil?
|
34
|
+
serialize_variables.each do |myattr|
|
35
|
+
val = opt[myattr[:id]]
|
36
|
+
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
37
|
+
end
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
def to_s
|
@@ -51,5 +57,8 @@ module FruitToLime
|
|
51
57
|
yield @status
|
52
58
|
end
|
53
59
|
|
60
|
+
def customer=(customer)
|
61
|
+
@customer = OrganizationReference.from_organization(customer)
|
62
|
+
end
|
54
63
|
end
|
55
64
|
end
|
@@ -1,7 +1,18 @@
|
|
1
1
|
module FruitToLime
|
2
2
|
class Note
|
3
3
|
include SerializeHelper
|
4
|
-
attr_accessor :id, :text, :integration_id, :classification, :date
|
4
|
+
attr_accessor :id, :text, :integration_id, :classification, :date
|
5
|
+
|
6
|
+
attr_reader :organization, :created_by, :person
|
7
|
+
|
8
|
+
def initialize(opt = nil)
|
9
|
+
if !opt.nil?
|
10
|
+
serialize_variables.each do |myattr|
|
11
|
+
val = opt[myattr[:id]]
|
12
|
+
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
5
16
|
|
6
17
|
def serialize_variables
|
7
18
|
[ :id, :text, :integration_id, :classification ].map {
|
@@ -30,5 +41,35 @@ module FruitToLime
|
|
30
41
|
def serialize_name
|
31
42
|
"Note"
|
32
43
|
end
|
44
|
+
|
45
|
+
def organization=(org)
|
46
|
+
@organization = OrganizationReference.from_organization(org)
|
47
|
+
end
|
48
|
+
|
49
|
+
def created_by=(coworker)
|
50
|
+
@created_by = CoworkerReference.from_coworker(coworker)
|
51
|
+
end
|
52
|
+
|
53
|
+
def person=(person)
|
54
|
+
@person = PersonReference.from_person(person)
|
55
|
+
end
|
56
|
+
|
57
|
+
def validate
|
58
|
+
error = String.new
|
59
|
+
|
60
|
+
if @text.nil? || @text.empty?
|
61
|
+
error = "Text is required for note\n"
|
62
|
+
end
|
63
|
+
|
64
|
+
if @created_by.nil?
|
65
|
+
error = "#{error}Created_by is required for note\n"
|
66
|
+
end
|
67
|
+
|
68
|
+
if @organization.nil?
|
69
|
+
error = "#{error}Organization is required for note\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
return error
|
73
|
+
end
|
33
74
|
end
|
34
75
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module FruitToLime
|
2
|
-
|
2
|
+
class OrganizationReference
|
3
3
|
include SerializeHelper
|
4
4
|
attr_accessor :id, :integration_id, :heading
|
5
5
|
def serialize_variables
|
@@ -9,7 +9,13 @@ module FruitToLime
|
|
9
9
|
}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
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
|
13
19
|
end
|
14
20
|
|
15
21
|
def to_s
|
@@ -19,6 +25,16 @@ module FruitToLime
|
|
19
25
|
def empty?
|
20
26
|
return !@integration_id && !@id && !@heading
|
21
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
|
22
38
|
end
|
23
39
|
|
24
40
|
class Organization
|
@@ -31,7 +47,13 @@ module FruitToLime
|
|
31
47
|
# you add custom values by using {#set_custom_value}
|
32
48
|
attr_reader :custom_values
|
33
49
|
|
34
|
-
def initialize()
|
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
|
35
57
|
end
|
36
58
|
|
37
59
|
def to_reference()
|
@@ -76,8 +98,8 @@ module FruitToLime
|
|
76
98
|
|
77
99
|
# @example Set the source to par id 4653
|
78
100
|
# o.with_source do |source|
|
79
|
-
# source.par_se('4653')
|
80
|
-
# end
|
101
|
+
# source.par_se('4653')
|
102
|
+
# end
|
81
103
|
# @see ReferenceToSource source
|
82
104
|
def with_source
|
83
105
|
@source = ReferenceToSource.new if @source == nil
|
@@ -87,7 +109,7 @@ module FruitToLime
|
|
87
109
|
# @example Set the responsible coworker of the organization to the coworker with integration id 943
|
88
110
|
# o.with_responsible_coworker do |responsible_coworker|
|
89
111
|
# responsible_coworker.integration_id = "943"
|
90
|
-
# end
|
112
|
+
# end
|
91
113
|
# @see CoworkerReference responsible_coworker
|
92
114
|
def with_responsible_coworker
|
93
115
|
@responsible_coworker = CoworkerReference.new if @responsible_coworker==nil
|
@@ -151,7 +173,7 @@ module FruitToLime
|
|
151
173
|
def to_s
|
152
174
|
return "#{name}"
|
153
175
|
end
|
154
|
-
|
176
|
+
|
155
177
|
def validate
|
156
178
|
error = String.new
|
157
179
|
|
@@ -8,22 +8,34 @@ module FruitToLime
|
|
8
8
|
|
9
9
|
def initalize()
|
10
10
|
end
|
11
|
+
|
11
12
|
def to_s
|
12
13
|
return "(#{id}, #{integration_id})"
|
13
14
|
end
|
15
|
+
|
14
16
|
def empty?
|
15
17
|
return !@integration_id && !@id
|
16
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 coworker.is?(PersonReference)
|
26
|
+
return person
|
27
|
+
end
|
28
|
+
end
|
17
29
|
end
|
18
30
|
|
19
31
|
class Person < PersonReference
|
20
32
|
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
21
33
|
attr_accessor :first_name, :last_name,
|
22
34
|
:direct_phone_number, :fax_phone_number, :mobile_phone_number, :home_phone_number,
|
23
|
-
:position, :email, :alternative_email, :postal_address, :currently_employed
|
24
|
-
|
35
|
+
:position, :email, :alternative_email, :postal_address, :currently_employed
|
36
|
+
|
25
37
|
# you add custom values by using {#set_custom_value}
|
26
|
-
attr_reader :custom_values
|
38
|
+
attr_reader :custom_values, :organization
|
27
39
|
|
28
40
|
def initialize(opt = nil)
|
29
41
|
@currently_employed = true
|
@@ -34,6 +46,11 @@ module FruitToLime
|
|
34
46
|
end
|
35
47
|
end
|
36
48
|
end
|
49
|
+
|
50
|
+
def organization=(org)
|
51
|
+
@organization = OrganizationReference.from_organization(org)
|
52
|
+
end
|
53
|
+
|
37
54
|
# @example Set city of postal address to 'Lund'
|
38
55
|
# p.with_postal_address do |addr|
|
39
56
|
# addr.city = "Lund"
|
@@ -46,8 +63,8 @@ module FruitToLime
|
|
46
63
|
|
47
64
|
# @example Set the source to par id 4653
|
48
65
|
# p.with_source do |source|
|
49
|
-
# source.par_se('4653')
|
50
|
-
# end
|
66
|
+
# source.par_se('4653')
|
67
|
+
# end
|
51
68
|
# @see ReferenceToSource source
|
52
69
|
def with_source
|
53
70
|
@source = ReferenceToSource.new if @source == nil
|
@@ -76,9 +93,9 @@ module FruitToLime
|
|
76
93
|
{:id => :home_phone_number, :type => :string},
|
77
94
|
|
78
95
|
{:id => :position, :type => :string},
|
79
|
-
|
96
|
+
|
80
97
|
{:id => :tags, :type => :tags},
|
81
|
-
|
98
|
+
|
82
99
|
{:id => :email, :type => :string},
|
83
100
|
{:id => :alternative_email, :type => :string},
|
84
101
|
|
@@ -86,7 +103,7 @@ module FruitToLime
|
|
86
103
|
{:id => :custom_values, :type => :custom_values},
|
87
104
|
{:id => :currently_employed, :type => :bool},
|
88
105
|
{:id => :organization, :type => :organization_reference},
|
89
|
-
|
106
|
+
|
90
107
|
]
|
91
108
|
end
|
92
109
|
|
@@ -126,7 +143,7 @@ module FruitToLime
|
|
126
143
|
|
127
144
|
splitted = name.split(' ')
|
128
145
|
@first_name = splitted[0]
|
129
|
-
if splitted.length > 1
|
146
|
+
if splitted.length > 1
|
130
147
|
@last_name = splitted.drop(1).join(' ')
|
131
148
|
end
|
132
149
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module FruitToLime
|
3
|
-
# The root model for Go import. This class is the container for everything else.
|
3
|
+
# The root model for Go import. This class is the container for everything else.
|
4
4
|
class RootModel
|
5
5
|
# the import_coworker is a special coworker that is set as
|
6
6
|
# responsible for objects that requires a coworker, eg a note.
|
7
7
|
attr_accessor :import_coworker
|
8
|
-
|
8
|
+
|
9
9
|
attr_accessor :settings, :organizations, :coworkers, :deals, :notes
|
10
10
|
def serialize_variables
|
11
11
|
[
|
@@ -43,7 +43,7 @@ module FruitToLime
|
|
43
43
|
# :last_name=>"Anka",
|
44
44
|
# :email=>"kalle.anka@vonanka.com"
|
45
45
|
# })
|
46
|
-
#
|
46
|
+
#
|
47
47
|
# @example Add a coworker from a new coworker
|
48
48
|
# coworker = FruitToLime::Coworker.new
|
49
49
|
# coworker.integration_id = "123"
|
@@ -67,19 +67,135 @@ module FruitToLime
|
|
67
67
|
end
|
68
68
|
|
69
69
|
coworker = Coworker.new(coworker) if !coworker.is_a?(Coworker)
|
70
|
-
|
71
|
-
if find_coworker_by_integration_id(coworker.integration_id)!=nil
|
70
|
+
|
71
|
+
if find_coworker_by_integration_id(coworker.integration_id) != nil
|
72
72
|
raise AlreadyAddedError, "Already added a coworker with integration_id #{coworker.integration_id}"
|
73
73
|
end
|
74
74
|
|
75
75
|
@coworkers.push(coworker)
|
76
|
+
|
77
|
+
return coworker
|
76
78
|
end
|
77
79
|
|
78
|
-
#
|
79
|
-
#
|
80
|
-
|
80
|
+
# Adds the specifed organization object to the model.
|
81
|
+
# @example Add an organization from a hash
|
82
|
+
# rootmodel.add_organization({
|
83
|
+
# :integration_id => "123",
|
84
|
+
# :name => "Beagle Boys",
|
85
|
+
# })
|
86
|
+
#
|
87
|
+
# @example Add an organization from a new organization
|
88
|
+
# organization = FruitToLime::Organization.new
|
89
|
+
# organization.integration_id = "123"
|
90
|
+
# organization.name = "Beagle Boys"
|
91
|
+
# rootmodel.add_organization(organization)
|
92
|
+
#
|
93
|
+
# @example If you want to keep adding organizations and dont
|
94
|
+
# care about duplicates not being added. Your model might not
|
95
|
+
# be saved due to duplicate integration_ids.
|
96
|
+
# begin
|
97
|
+
# rootmodel.add_organization(organization)
|
98
|
+
# rescue FruitToLime::AlreadyAddedError
|
99
|
+
# puts "Warning: already added organization"
|
100
|
+
# end
|
101
|
+
# @see Coworker
|
102
|
+
def add_organization(organization)
|
103
|
+
@organizations = [] if @organizations.nil?
|
104
|
+
|
105
|
+
if organization.nil?
|
106
|
+
raise "Missing organization to add"
|
107
|
+
end
|
108
|
+
|
109
|
+
organization = Organization.new(organization) if !organization.is_a?(Organization)
|
110
|
+
|
111
|
+
if find_organization_by_integration_id(organization.integration_id) != nil
|
112
|
+
raise AlreadyAddedError, "Already added an organization with integration_id #(organization.integration_id)"
|
113
|
+
end
|
114
|
+
|
115
|
+
@organizations.push(organization)
|
116
|
+
|
117
|
+
return organization
|
118
|
+
end
|
119
|
+
|
120
|
+
# Adds the specifed deal object to the model.
|
121
|
+
# @example Add an deal from a hash
|
122
|
+
# rootmodel.add_deal({
|
123
|
+
# :integration_id => "123",
|
124
|
+
# :name => "Big deal",
|
125
|
+
# })
|
126
|
+
#
|
127
|
+
# @example Add a deal from a new deal
|
128
|
+
# deal = FruitToLime::Deal.new
|
129
|
+
# deal.integration_id = "123"
|
130
|
+
# deal.name = "Big deal"
|
131
|
+
# rootmodel.add_deal(deal)
|
132
|
+
#
|
133
|
+
# @example If you want to keep adding deals and dont
|
134
|
+
# care about duplicates not being added. Your model might not
|
135
|
+
# be saved due to duplicate integration_ids.
|
136
|
+
# begin
|
137
|
+
# rootmodel.add_deal(deal)
|
138
|
+
# rescue FruitToLime::AlreadyAddedError
|
139
|
+
# puts "Warning: already added deal"
|
140
|
+
# end
|
141
|
+
# @see Coworker
|
142
|
+
def add_deal(deal)
|
143
|
+
@deals = [] if @deals.nil?
|
144
|
+
|
145
|
+
if deal.nil?
|
146
|
+
raise "Missing deal to add"
|
147
|
+
end
|
148
|
+
|
149
|
+
deal = Deal.new(deal) if !deal.is_a?(Deal)
|
150
|
+
|
151
|
+
if find_deal_by_integration_id(deal.integration_id) != nil
|
152
|
+
raise AlreadyAddedError, "Already added a deal with integration_id #{deal.integration_id}"
|
153
|
+
end
|
154
|
+
|
155
|
+
@deals.push(deal)
|
156
|
+
|
157
|
+
return deal
|
158
|
+
end
|
159
|
+
|
160
|
+
# Adds the specifed note object to the model.
|
161
|
+
# @example Add an deal from a hash
|
162
|
+
# rootmodel.add_note({
|
163
|
+
# :integration_id => "123",
|
164
|
+
# :text => "This is a note",
|
165
|
+
# })
|
166
|
+
#
|
167
|
+
# @example Add a note from a new note
|
168
|
+
# note = FruitToLime::Note.new
|
169
|
+
# note.integration_id = "123"
|
170
|
+
# note.text = "Big deal"
|
171
|
+
# rootmodel.add_note(note)
|
172
|
+
#
|
173
|
+
# @example If you want to keep adding deals and dont
|
174
|
+
# care about duplicates not being added. Your model might not
|
175
|
+
# be saved due to duplicate integration_ids.
|
176
|
+
# begin
|
177
|
+
# rootmodel.add_deal(deal)
|
178
|
+
# rescue FruitToLime::AlreadyAddedError
|
179
|
+
# puts "Warning: already added deal"
|
180
|
+
# end
|
181
|
+
# @see Coworker
|
182
|
+
def add_note(note)
|
81
183
|
@notes = [] if @notes == nil
|
82
|
-
|
184
|
+
|
185
|
+
if note.nil?
|
186
|
+
raise "Missing note to add"
|
187
|
+
end
|
188
|
+
|
189
|
+
note = Note.new(note) if !note.is_a?(Note)
|
190
|
+
|
191
|
+
if (!note.integration_id.nil? && note.integration_id.length > 0) &&
|
192
|
+
find_note_by_integration_id(note.integration_id) != nil
|
193
|
+
raise AlreadyAddedError, "Already added a note with integration_id #{note.integration_id}"
|
194
|
+
end
|
195
|
+
|
196
|
+
@notes.push(note)
|
197
|
+
|
198
|
+
return note
|
83
199
|
end
|
84
200
|
|
85
201
|
def with_new_note
|
@@ -102,6 +218,12 @@ module FruitToLime
|
|
102
218
|
end
|
103
219
|
end
|
104
220
|
|
221
|
+
def find_note_by_integration_id(integration_id)
|
222
|
+
return @notes.find do |note|
|
223
|
+
note.integration_id == integration_id
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
105
227
|
# find deals for organization using {Organization#integration_id}
|
106
228
|
def find_deals_for_organization(organization)
|
107
229
|
deals = []
|
@@ -113,6 +235,12 @@ module FruitToLime
|
|
113
235
|
return deals
|
114
236
|
end
|
115
237
|
|
238
|
+
def find_deal_by_integration_id(integration_id)
|
239
|
+
return @deals.find do |deal|
|
240
|
+
deal.integration_id == integration_id
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
116
244
|
# Returns a string describing problems with the data. For instance if integration_id for any entity is not unique.
|
117
245
|
def sanity_check
|
118
246
|
error = String.new
|
@@ -164,6 +292,14 @@ module FruitToLime
|
|
164
292
|
end
|
165
293
|
end
|
166
294
|
|
295
|
+
@notes.each do |note|
|
296
|
+
validation_message = note.validate
|
297
|
+
|
298
|
+
if !validation_message.empty?
|
299
|
+
error = "#{error}\n#{validation_message}"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
167
303
|
return error.strip
|
168
304
|
end
|
169
305
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'global_phone'
|
2
|
+
|
3
|
+
module FruitToLime
|
4
|
+
# The PhoneHelper helps you parse and format phone number strings
|
5
|
+
# into pretty looking numbers.
|
6
|
+
class PhoneHelper
|
7
|
+
GlobalPhone.db_path = File.join(File.dirname(__FILE__), 'global_phone.json')
|
8
|
+
GlobalPhone.default_territory_name = :se
|
9
|
+
|
10
|
+
# Sets the country code used during parsning. The default is
|
11
|
+
# swedish (:se) and if you are parsing swedish numbers you
|
12
|
+
# dont need to set the country code.
|
13
|
+
def self.set_country_code(country_code)
|
14
|
+
GlobalPhone.default_territory_name = country_code
|
15
|
+
end
|
16
|
+
|
17
|
+
# Parses the specifed number_string and returns only valid
|
18
|
+
# numbers.
|
19
|
+
# @see parse_numbers
|
20
|
+
def self.parse_numbers_strict(number_string, delimiters = ',')
|
21
|
+
parse_numbers number_string, delimiters, true
|
22
|
+
end
|
23
|
+
|
24
|
+
# Parses the specified number_string into one or more phone
|
25
|
+
# numbers using the specified delimiters. If strict_mode is
|
26
|
+
# true only valid numbers are returned, otherwise are invalid
|
27
|
+
# numbers returned as found in the number_string.
|
28
|
+
#
|
29
|
+
# @example Parse a number
|
30
|
+
# number = FruitToLime::PhoneHelper.parse_numbers("046 - 270 48 00")
|
31
|
+
#
|
32
|
+
# @example Parses a string with two numbers and a custom delimiter
|
33
|
+
# source = "046 - 270 48 00/ 031-712 44 00"
|
34
|
+
# number1, number2 = FruitToLime::PhoneHelper.parse_numbers(source, '/')
|
35
|
+
def self.parse_numbers(number_string, delimiters = ',', strict_mode = false)
|
36
|
+
numbers = []
|
37
|
+
|
38
|
+
if delimiters.is_a?(Array)
|
39
|
+
# we have several delimiters, replace all delimiters
|
40
|
+
# in the number_string with the first delimiter
|
41
|
+
delimiters.each do |del|
|
42
|
+
number_string = number_string.sub(del, delimiters[0])
|
43
|
+
end
|
44
|
+
delimiter = delimiters[0]
|
45
|
+
elsif delimiters.is_a?(String)
|
46
|
+
delimiter = delimiters
|
47
|
+
else
|
48
|
+
raise "delimiters should be either a string or and array of strings"
|
49
|
+
end
|
50
|
+
|
51
|
+
number_string.split(delimiter).each do |possible_number|
|
52
|
+
if !possible_number.empty?
|
53
|
+
number = GlobalPhone.parse([possible_number])
|
54
|
+
|
55
|
+
if !number.nil? && number.valid?
|
56
|
+
numbers.push number.to_s
|
57
|
+
else
|
58
|
+
if !strict_mode
|
59
|
+
numbers.push possible_number
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if numbers.length == 0
|
66
|
+
return ""
|
67
|
+
elsif numbers.length == 1
|
68
|
+
return numbers[0]
|
69
|
+
else
|
70
|
+
return numbers
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/fruit_to_lime.rb
CHANGED
@@ -3,12 +3,15 @@ module FruitToLime
|
|
3
3
|
def self.require_all_in(folder)
|
4
4
|
Dir.glob(File.join( File.dirname(File.absolute_path(__FILE__)),folder), &method(:require))
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
require 'fruit_to_lime/errors'
|
8
8
|
require 'fruit_to_lime/serialize_helper'
|
9
9
|
require 'fruit_to_lime/model_helpers'
|
10
10
|
FruitToLime::require_all_in 'fruit_to_lime/model/*.rb'
|
11
11
|
require 'fruit_to_lime/csv_helper'
|
12
12
|
require 'fruit_to_lime/roo_helper'
|
13
|
+
require 'fruit_to_lime/phone_helper'
|
14
|
+
require 'fruit_to_lime/email_helper'
|
15
|
+
require 'fruit_to_lime/excel_helper'
|
13
16
|
require 'fruit_to_lime/templating'
|
14
17
|
end
|
data/spec/class_settings_spec.rb
CHANGED
@@ -7,11 +7,31 @@ describe "ClassSettings" do
|
|
7
7
|
}
|
8
8
|
|
9
9
|
it "can set custom field and if there is already an existing custom field, then it is overwritten." do
|
10
|
-
class_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
|
11
|
-
class_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system 2"})
|
10
|
+
class_settings.set_custom_field({:integration_id => "link_to_bi_system", :title => "Link to BI system"})
|
11
|
+
class_settings.set_custom_field({:integration_id => "link_to_bi_system", :title => "Link to BI system 2"})
|
12
12
|
class_settings.custom_fields.length.should eq 1
|
13
|
-
class_settings.custom_fields[0].title.should eq "Link to BI system 2"
|
13
|
+
class_settings.custom_fields[0].title.should eq "Link to BI system 2"
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should not allow new custom fields without id and integration id" do
|
17
|
+
begin
|
18
|
+
class_settings.set_custom_field({:integration_id => "", :id => "", :title => "Link to BI system"})
|
19
|
+
rescue
|
20
|
+
end
|
21
|
+
|
22
|
+
class_settings.custom_fields.length.should eq 0
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should allow new custom field with integration_id" do
|
26
|
+
class_settings.set_custom_field({:integration_id => "link_to_bi_system", :title => "Link to BI system"})
|
27
|
+
class_settings.custom_fields.length.should eq 1
|
28
|
+
class_settings.custom_fields[0].title.should eq "Link to BI system"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should allow new custom field with id" do
|
32
|
+
class_settings.set_custom_field({:id => "123", :title => "Link to BI system"})
|
33
|
+
class_settings.custom_fields.length.should eq 1
|
34
|
+
class_settings.custom_fields[0].title.should eq "Link to BI system"
|
35
|
+
end
|
16
36
|
end
|
17
37
|
|