fruit_to_lime 0.8.2 → 0.9.0

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 (46) hide show
  1. data/bin/fruit_to_lime +24 -24
  2. data/lib/fruit_to_lime/address_helper.rb +17 -17
  3. data/lib/fruit_to_lime/csv_helper.rb +32 -32
  4. data/lib/fruit_to_lime/model/address.rb +37 -37
  5. data/lib/fruit_to_lime/model/coworker.rb +44 -0
  6. data/lib/fruit_to_lime/model/coworker_reference.rb +17 -14
  7. data/lib/fruit_to_lime/model/customfield.rb +30 -29
  8. data/lib/fruit_to_lime/model/deal.rb +49 -0
  9. data/lib/fruit_to_lime/model/note.rb +38 -27
  10. data/lib/fruit_to_lime/model/organization.rb +140 -121
  11. data/lib/fruit_to_lime/model/person.rb +115 -111
  12. data/lib/fruit_to_lime/model/referencetosource.rb +42 -42
  13. data/lib/fruit_to_lime/model/rootmodel.rb +142 -39
  14. data/lib/fruit_to_lime/model/tag.rb +33 -28
  15. data/lib/fruit_to_lime/model_helpers.rb +19 -0
  16. data/lib/fruit_to_lime/roo_helper.rb +59 -54
  17. data/lib/fruit_to_lime/serialize_helper.rb +139 -139
  18. data/lib/fruit_to_lime/templating.rb +51 -51
  19. data/lib/fruit_to_lime.rb +13 -12
  20. data/spec/helpers/address_helper_spec.rb +48 -48
  21. data/spec/helpers/csv_helper_spec.rb +15 -15
  22. data/spec/helpers/roo_helper_spec.rb +10 -10
  23. data/spec/helpers/serialize_helper_spec.rb +211 -211
  24. data/spec/person_spec.rb +44 -44
  25. data/spec/spec_helper.rb +24 -24
  26. data/spec/templating_spec.rb +40 -40
  27. data/templates/csv/Gemfile +5 -5
  28. data/templates/csv/Rakefile.rb +7 -7
  29. data/templates/csv/convert.rb +2 -2
  30. data/templates/csv/lib/tomodel.rb +56 -42
  31. data/templates/csv/spec/sample_data/organizations.csv +2 -2
  32. data/templates/csv/spec/spec_helper.rb +24 -24
  33. data/templates/csv/spec/tomodel_spec.rb +14 -14
  34. data/templates/excel/Gemfile +6 -6
  35. data/templates/excel/Rakefile.rb +7 -7
  36. data/templates/excel/convert.rb +2 -2
  37. data/templates/excel/lib/tomodel.rb +53 -39
  38. data/templates/excel/spec/spec_helper.rb +20 -20
  39. data/templates/excel/spec/tomodel_spec.rb +18 -18
  40. data/templates/sqlserver/Gemfile +6 -6
  41. data/templates/sqlserver/Rakefile.rb +7 -7
  42. data/templates/sqlserver/convert.rb +2 -2
  43. data/templates/sqlserver/lib/tomodel.rb +67 -53
  44. data/templates/sqlserver/spec/spec_helper.rb +20 -20
  45. data/templates/sqlserver/spec/tomodel_spec.rb +9 -9
  46. metadata +23 -4
@@ -1,121 +1,140 @@
1
- module FruitToLime
2
- class OrganizationReference
3
- include SerializeHelper
4
- attr_accessor :id, :integration_id, :name
5
- def serialize_variables
6
- [ :id, :integration_id, :name ].map { |prop| {:id=>prop,:type=>:string} }
7
- end
8
-
9
- def initalize()
10
- end
11
- def to_s
12
- return "(#{id}, #{integration_id}, #{name})"
13
- end
14
- def empty?
15
- return !@integration_id && !@id && !@name
16
- end
17
- def same_as_this_method()
18
- if @integration_id
19
- return lambda { |org|
20
- org.integration_id == @integration_id
21
- }
22
- elsif @id
23
- return lambda { |org|
24
- org.id == @id
25
- }
26
- elsif @name
27
- return lambda { |org|
28
- org.name == @name
29
- }
30
- else
31
- raise "No reference!"
32
- end
33
- end
34
- end
35
-
36
- class Organization < OrganizationReference
37
- include SerializeHelper
38
-
39
- attr_accessor :organization_number, :email, :web_site, :external_link, :postal_address, :visit_address
40
- attr_reader :employees, :notes, :custom_fields
41
-
42
- def initialize()
43
- end
44
-
45
- def with_postal_address
46
- @postal_address = Address.new
47
- yield @postal_address
48
- end
49
-
50
- def with_visit_address
51
- @visit_address = Address.new
52
- yield @visit_address
53
- end
54
-
55
- def set_custom_field(obj)
56
- @custom_fields = [] if @custom_fields==nil
57
- @custom_fields.push CustomField.new(obj)
58
- end
59
-
60
- def with_source
61
- @source = ReferenceToSource.new
62
- yield @source
63
- end
64
-
65
- def add_employee(val)
66
- @employees = [] if @employees==nil
67
- @employees.push(if val.is_a? Person then val else Person.new(val) end)
68
- end
69
-
70
- def tags
71
- @tags
72
- end
73
-
74
- def add_tag(str)
75
- @tags = [] if @tags == nil
76
- @tags.push(Tag.new(str))
77
- end
78
-
79
- def serialize_variables
80
- [
81
- :id, :integration_id, :name, :organization_number, :external_link, :email, :web_site ].map {
82
- |prop| { :id => prop, :type => :string }
83
- } +
84
- [
85
- { :id => :postal_address, :type => :address},
86
- { :id => :visit_address, :type => :address},
87
- { :id => :employees, :type => :persons},
88
- { :id => :tags, :type => :tags},
89
- { :id => :custom_fields, :type => :custom_fields},
90
- { :id => :source, :type => :source_ref}
91
- ]
92
- end
93
-
94
- def serialize_name
95
- "Organization"
96
- end
97
-
98
- def to_s
99
- return "#{name}"
100
- end
101
-
102
- def validate
103
- error = String.new
104
-
105
- if @name.nil? || @name.empty?
106
- error = "A name is required for organization.\n#{serialize()}"
107
- end
108
-
109
- if @employees != nil
110
- @employees.each do |person|
111
- validation_message = person.validate()
112
- if !validation_message.empty?
113
- error = "#{error}\n#{validation_message}"
114
- end
115
- end
116
- end
117
-
118
- return error
119
- end
120
- end
121
- 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 initalize()
13
+ end
14
+
15
+ def to_s
16
+ return "(#{id}, #{integration_id}, #{heading})"
17
+ end
18
+
19
+ def empty?
20
+ return !@integration_id && !@id && !@heading
21
+ end
22
+
23
+ # *** TODO: delete this?
24
+ def same_as_this_method()
25
+ if @integration_id
26
+ return lambda { |org|
27
+ org.integration_id == @integration_id
28
+ }
29
+ elsif @id
30
+ return lambda { |org|
31
+ org.id == @id
32
+ }
33
+ elsif @heading
34
+ return lambda { |org|
35
+ org.heading == @heading
36
+ }
37
+ else
38
+ raise "No reference!"
39
+ end
40
+ end
41
+ end
42
+
43
+ class Organization
44
+ include SerializeHelper, ModelHasCustomFields, ModelHasTags
45
+
46
+ attr_accessor :id, :integration_id, :name, :organization_number, :email, :web_site, :external_link,
47
+ :postal_address, :visit_address, :central_phone_number, :responsible_coworker, :source_data
48
+
49
+ attr_reader :employees
50
+
51
+ def initialize()
52
+ end
53
+
54
+ def to_reference()
55
+ reference = OrganizationReference.new
56
+ reference.id = @id
57
+ reference.integration_id = @integration_id
58
+ reference.heading = @name
59
+ return reference
60
+ end
61
+
62
+ def ==(that)
63
+ if that.nil?
64
+ return false
65
+ end
66
+
67
+ if that.is_a? Organization
68
+ return @integration_id == that.integration_id
69
+ elsif that.is_a? String
70
+ return @integration_id == that
71
+ end
72
+
73
+ return false
74
+ end
75
+
76
+ def with_postal_address
77
+ @postal_address = Address.new
78
+ yield @postal_address
79
+ end
80
+
81
+ def with_visit_address
82
+ @visit_address = Address.new
83
+ yield @visit_address
84
+ end
85
+
86
+ def with_source
87
+ @source = ReferenceToSource.new
88
+ yield @source
89
+ end
90
+
91
+ def add_employee(val)
92
+ @employees = [] if @employees==nil
93
+ @employees.push(if val.is_a? Person then val else Person.new(val) end)
94
+ end
95
+
96
+ def serialize_variables
97
+ [
98
+ :id, :integration_id, :name, :organization_number, :external_link,
99
+ :email, :web_site, :central_phone_number ].map {
100
+ |prop| { :id => prop, :type => :string }
101
+ } +
102
+ [
103
+ { :id => :postal_address, :type => :address },
104
+ { :id => :visit_address, :type => :address },
105
+ { :id => :employees, :type => :persons },
106
+ { :id => :tags, :type => :tags },
107
+ { :id => :custom_fields, :type => :custom_fields },
108
+ { :id => :source, :type => :source_ref },
109
+ { :id => :responsible_coworker, :type => :coworker_reference}
110
+ ]
111
+ end
112
+
113
+ def serialize_name
114
+ "Organization"
115
+ end
116
+
117
+ def to_s
118
+ return "#{name}"
119
+ end
120
+
121
+ def validate
122
+ error = String.new
123
+
124
+ if @name.nil? || @name.empty?
125
+ error = "A name is required for organization.\n#{serialize()}"
126
+ end
127
+
128
+ if @employees != nil
129
+ @employees.each do |person|
130
+ validation_message = person.validate()
131
+ if !validation_message.empty?
132
+ error = "#{error}\n#{validation_message}"
133
+ end
134
+ end
135
+ end
136
+
137
+ return error
138
+ end
139
+ end
140
+ end
@@ -1,111 +1,115 @@
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
- def to_s
12
- return "(#{id}, #{integration_id})"
13
- end
14
- def empty?
15
- return !@integration_id && !@id
16
- end
17
- def same_as_this_method()
18
- if @integration_id
19
- return lambda { |person|
20
- person.integration_id == @integration_id
21
- }
22
- elsif @id
23
- return lambda { |person|
24
- person.id == @id
25
- }
26
- else
27
- raise "No reference!"
28
- end
29
- end
30
- end
31
-
32
- class Person < PersonReference
33
- include SerializeHelper
34
- attr_accessor :first_name, :last_name,
35
- :direct_phone_number, :fax_phone_number, :mobile_phone_number, :home_phone_number,
36
- :position, :email, :alternative_email, :postal_address, :currently_employed,
37
- :notes, :organization
38
- attr_reader :custom_fields
39
-
40
- def initialize(opt=nil)
41
- if opt!=nil
42
- serialize_variables.each do |myattr|
43
- val = opt[myattr[:id]]
44
- instance_variable_set("@"+myattr[:id].to_s,val) if val!=nil
45
- end
46
- end
47
- end
48
-
49
- def with_postal_address
50
- @postal_address = Address.new
51
- yield @postal_address
52
- end
53
-
54
- def set_custom_field(obj)
55
- @custom_fields = [] if @custom_fields==nil
56
- @custom_fields.push CustomField.new(obj)
57
- end
58
-
59
- def with_source
60
- @source = ReferenceToSource.new
61
- yield @source
62
- end
63
-
64
- def tags
65
- @tags
66
- end
67
-
68
- def add_tag(str)
69
- @tags = [] if @tags == nil
70
- @tags.push(Tag.new(str))
71
- end
72
-
73
- def serialize_name
74
- "Person"
75
- end
76
-
77
- def serialize_variables
78
- [ :id, :integration_id, :first_name, :last_name,
79
- :direct_phone_number, :fax_phone_number, :mobile_phone_number, :home_phone_number,
80
- :position, :email, :alternative_email].map { |prop| {:id=>prop,:type=>:string} } +
81
- [{:id=>:postal_address,:type=>:address},
82
- {:id=>:currently_employed,:type=>:bool},
83
- #{:id=>:notes,:type=>:notes},
84
- {:id=>:tags,:type=>:tags},
85
- {:id=>:custom_fields,:type=>:custom_fields},
86
- {:id=>:source, :type=> :source_ref}
87
- ]
88
- end
89
-
90
- def get_import_rows
91
- (serialize_variables+[{:id=>:organization, :type=>:organization_reference}]).map do |p|
92
- map_to_row p
93
- end
94
- end
95
-
96
- def to_s
97
- return "#{first_name} #{last_name}"
98
- end
99
-
100
- def validate
101
- error = String.new
102
-
103
- if (@first_name.nil? || @first_name.empty?) &&
104
- (@last_name.nil? || @last_name.empty?)
105
- error = "A firstname or lastname is required for person.\n#{serialize()}"
106
- end
107
-
108
- return error
109
- end
110
- end
111
- 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
+ def to_s
12
+ return "(#{id}, #{integration_id})"
13
+ end
14
+ def empty?
15
+ return !@integration_id && !@id
16
+ end
17
+ def same_as_this_method()
18
+ if @integration_id
19
+ return lambda { |person|
20
+ person.integration_id == @integration_id
21
+ }
22
+ elsif @id
23
+ return lambda { |person|
24
+ person.id == @id
25
+ }
26
+ else
27
+ raise "No reference!"
28
+ end
29
+ end
30
+ end
31
+
32
+ class Person < PersonReference
33
+ include SerializeHelper
34
+ attr_accessor :first_name, :last_name,
35
+ :direct_phone_number, :fax_phone_number, :mobile_phone_number, :home_phone_number,
36
+ :position, :email, :alternative_email, :postal_address, :currently_employed,
37
+ :organization
38
+ attr_reader :custom_fields
39
+
40
+ def initialize(opt = nil)
41
+ if opt != nil
42
+ serialize_variables.each do |myattr|
43
+ val = opt[myattr[:id]]
44
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
45
+ end
46
+ end
47
+ end
48
+
49
+ def with_postal_address
50
+ @postal_address = Address.new
51
+ yield @postal_address
52
+ end
53
+
54
+ def set_custom_field(obj)
55
+ @custom_fields = [] if @custom_fields==nil
56
+ @custom_fields.push CustomField.new(obj)
57
+ end
58
+
59
+ def with_source
60
+ @source = ReferenceToSource.new
61
+ yield @source
62
+ end
63
+
64
+ def tags
65
+ @tags
66
+ end
67
+
68
+ def add_tag(str)
69
+ @tags = [] if @tags == nil
70
+ @tags.push(Tag.new(str))
71
+ end
72
+
73
+ def serialize_name
74
+ "Person"
75
+ end
76
+
77
+ def serialize_variables
78
+ [
79
+ :id, :integration_id, :first_name, :last_name,
80
+ :direct_phone_number, :fax_phone_number, :mobile_phone_number, :home_phone_number,
81
+ :position, :email, :alternative_email
82
+ ].map {
83
+ |prop| {:id => prop, :type => :string}
84
+ }+[
85
+ {:id => :postal_address, :type => :address},
86
+ {:id => :currently_employed, :type => :bool},
87
+ {:id => :tags, :type => :tags},
88
+ {:id => :custom_fields, :type => :custom_fields},
89
+ {:id => :source, :type => :source_ref},
90
+ {:id => :organization, :type => :organization_reference}
91
+ ]
92
+ end
93
+
94
+ def get_import_rows
95
+ (serialize_variables + [ { :id => :organization, :type => :organization_reference } ]).map do |p|
96
+ map_to_row p
97
+ end
98
+ end
99
+
100
+ def to_s
101
+ return "#{first_name} #{last_name}"
102
+ end
103
+
104
+ def validate
105
+ error = String.new
106
+
107
+ if (@first_name.nil? || @first_name.empty?) &&
108
+ (@last_name.nil? || @last_name.empty?)
109
+ error = "A firstname or lastname is required for person.\n#{serialize()}"
110
+ end
111
+
112
+ return error
113
+ end
114
+ end
115
+ end
@@ -1,43 +1,43 @@
1
- module FruitToLime
2
- class ReferenceToSource
3
- include SerializeHelper
4
- attr_accessor :name, :id, :format
5
-
6
- def serialize_variables
7
- [:name, :id, :format].map { |prop| { :id => prop, :type => :string } }
8
- end
9
-
10
- def serialize_name
11
- "ReferenceToSource"
12
- end
13
-
14
- def get_import_rows
15
- (serialize_variables + [{ :id => :value, :type => :string }]).map do |p|
16
- map_to_row p
17
- end
18
- end
19
-
20
- def initialize(opt = nil)
21
- if opt != nil
22
- serialize_variables.each do |myattr|
23
- val = opt[myattr[:id]]
24
- instance_variable_set("@" + myattr[:id].to_s,val) if val != nil
25
- end
26
- end
27
- end
28
-
29
- def to_s
30
- return "#{@name}_#{@format}_#{@id}"
31
- end
32
-
33
- def ==(other)
34
- return @name == other.name && @id == other.id && @format== other.format
35
- end
36
-
37
- def par_se(id)
38
- @name = 'pase'
39
- @format = 'External'
40
- @id = id
41
- end
42
- end
1
+ module FruitToLime
2
+ class ReferenceToSource
3
+ include SerializeHelper
4
+ attr_accessor :name, :id, :format
5
+
6
+ def serialize_variables
7
+ [:name, :id, :format].map { |prop| { :id => prop, :type => :string } }
8
+ end
9
+
10
+ def serialize_name
11
+ "ReferenceToSource"
12
+ end
13
+
14
+ def get_import_rows
15
+ (serialize_variables + [{ :id => :value, :type => :string }]).map do |p|
16
+ map_to_row p
17
+ end
18
+ end
19
+
20
+ def initialize(opt = nil)
21
+ if opt != nil
22
+ serialize_variables.each do |myattr|
23
+ val = opt[myattr[:id]]
24
+ instance_variable_set("@" + myattr[:id].to_s,val) if val != nil
25
+ end
26
+ end
27
+ end
28
+
29
+ def to_s
30
+ return "#{@name}_#{@format}_#{@id}"
31
+ end
32
+
33
+ def ==(other)
34
+ return @name == other.name && @id == other.id && @format== other.format
35
+ end
36
+
37
+ def par_se(id)
38
+ @name = 'pase'
39
+ @format = 'External'
40
+ @id = id
41
+ end
42
+ end
43
43
  end