fruit_to_lime 0.9.1 → 0.9.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 (44) 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 -44
  6. data/lib/fruit_to_lime/model/coworker_reference.rb +17 -17
  7. data/lib/fruit_to_lime/model/customfield.rb +30 -30
  8. data/lib/fruit_to_lime/model/note.rb +38 -38
  9. data/lib/fruit_to_lime/model/organization.rb +140 -140
  10. data/lib/fruit_to_lime/model/person.rb +115 -115
  11. data/lib/fruit_to_lime/model/referencetosource.rb +42 -42
  12. data/lib/fruit_to_lime/model/rootmodel.rb +142 -142
  13. data/lib/fruit_to_lime/model/tag.rb +33 -33
  14. data/lib/fruit_to_lime/model_helpers.rb +19 -19
  15. data/lib/fruit_to_lime/roo_helper.rb +59 -59
  16. data/lib/fruit_to_lime/serialize_helper.rb +139 -139
  17. data/lib/fruit_to_lime/templating.rb +51 -51
  18. data/lib/fruit_to_lime.rb +13 -13
  19. data/spec/helpers/address_helper_spec.rb +48 -48
  20. data/spec/helpers/csv_helper_spec.rb +15 -15
  21. data/spec/helpers/roo_helper_spec.rb +10 -10
  22. data/spec/helpers/serialize_helper_spec.rb +211 -211
  23. data/spec/person_spec.rb +44 -44
  24. data/spec/spec_helper.rb +24 -24
  25. data/templates/csv/Gemfile +5 -5
  26. data/templates/csv/Rakefile.rb +7 -7
  27. data/templates/csv/convert.rb +2 -2
  28. data/templates/csv/lib/tomodel.rb +56 -56
  29. data/templates/csv/spec/sample_data/organizations.csv +2 -2
  30. data/templates/csv/spec/spec_helper.rb +24 -24
  31. data/templates/csv/spec/tomodel_spec.rb +14 -14
  32. data/templates/excel/Gemfile +6 -6
  33. data/templates/excel/Rakefile.rb +7 -7
  34. data/templates/excel/convert.rb +2 -2
  35. data/templates/excel/lib/tomodel.rb +53 -53
  36. data/templates/excel/spec/spec_helper.rb +20 -20
  37. data/templates/excel/spec/tomodel_spec.rb +18 -18
  38. data/templates/sqlserver/Gemfile +6 -6
  39. data/templates/sqlserver/Rakefile.rb +7 -7
  40. data/templates/sqlserver/convert.rb +2 -2
  41. data/templates/sqlserver/lib/tomodel.rb +67 -67
  42. data/templates/sqlserver/spec/spec_helper.rb +20 -20
  43. data/templates/sqlserver/spec/tomodel_spec.rb +9 -9
  44. metadata +2 -2
@@ -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
@@ -1,142 +1,142 @@
1
- module FruitToLime
2
- class RootModel
3
- # the import_coworker is a special coworker that is set as
4
- # responsible for objects that requires a coworker, eg a note.
5
- attr_accessor :organizations, :coworkers, :deals, :notes, :import_coworker
6
- def serialize_variables
7
- [
8
- {:id => :coworkers, :type => :coworkers},
9
- {:id => :organizations, :type => :organizations},
10
- {:id => :deals, :type => :deals},
11
- {:id => :notes, :type => :notes},
12
- ]
13
- end
14
-
15
- def serialize_name
16
- "GoImport"
17
- end
18
-
19
- include SerializeHelper
20
-
21
- def initialize()
22
- @organizations = []
23
- @coworkers = []
24
- @import_coworker = Coworker.new
25
- @import_coworker.integration_id = "import"
26
- @import_coworker.first_name = "Import"
27
- @coworkers.push @import_coworker
28
- @deals = []
29
- @notes = []
30
- end
31
-
32
- # Adds the specifed coworker object to the model.
33
- def add_coworker(coworker)
34
- @coworkers = [] if @coworkers == nil
35
-
36
- if coworker != nil && coworker.is_a?(Coworker) && !@coworkers.include?(coworker)
37
- @coworkers.push(coworker)
38
- end
39
- end
40
-
41
- def add_note(text)
42
- @notes = [] if @notes == nil
43
- @notes.push(if text.is_a? Note then text else Note.new(text) end)
44
- end
45
-
46
- def with_note
47
- @notes = [] if @notes == nil
48
-
49
- note = Note.new
50
- @notes.push note
51
- yield note
52
- end
53
-
54
- # *** TODO:
55
- #
56
- # delete find_organization_by_reference and
57
- #same_as_this_method from organization?
58
- def find_organization_by_reference(organization_reference)
59
- same_as_this = organization_reference.same_as_this_method
60
- return @organizations.find do |org|
61
- same_as_this.call(org)
62
- end
63
- end
64
-
65
- def find_coworker_by_integration_id(integration_id)
66
- return @coworkers.find do |coworker|
67
- coworker == integration_id
68
- end
69
- end
70
-
71
- def find_organization_by_integration_id(integration_id)
72
- return @organizations.find do |organization|
73
- organization == integration_id
74
- end
75
- end
76
-
77
- def find_deals_for_organization(organization)
78
- deals = []
79
-
80
- deals = @deals.select do |deal|
81
- !deal.customer.nil? && deal.customer.integration_id == organization.integration_id
82
- end
83
-
84
- return deals
85
- end
86
-
87
- def sanity_check
88
- error = String.new
89
-
90
- dups = get_duplicates(@coworkers) {|coworker| coworker.integration_id}
91
- dups_error_items = (dups.collect{|coworker| coworker.integration_id}).compact
92
- if dups.length > 0
93
- error = "#{error}\nDuplicate coworker integration_id: #{dups_error_items.join(", ")}."
94
- end
95
-
96
- dups = get_duplicates(@organizations) {|org| org.integration_id}
97
- dups_error_items = (dups.collect{|org| org.integration_id}).compact
98
- if dups.length > 0
99
- error = "#{error}\nDuplicate organization integration_id: #{dups_error_items.join(", ")}."
100
- end
101
-
102
- dups = get_duplicates(@deals) {|deal| deal.integration_id}
103
- dups_error_items = (dups.collect{|deal| deal.integration_id}).compact
104
- if dups_error_items.length > 0
105
- error = "#{error}\nDuplicate deal integration_id: #{dups_error_items.join(", ")}."
106
- end
107
-
108
- return error.strip
109
- end
110
-
111
- # returns all items from the object array with duplicate keys.
112
- # To get all organizations with the same integration_id use
113
- # get_duplicates(organizations, {|org| org.integration_id})
114
- def get_duplicates(objects, &key)
115
- uniq_items = objects.uniq {|item| key.call(item)}.compact
116
-
117
- return (objects - uniq_items).compact
118
- end
119
-
120
- def validate()
121
- error = String.new
122
-
123
- @organizations.each do |o|
124
- validation_message = o.validate()
125
-
126
- if !validation_message.empty?
127
- error = "#{error}\n#{validation_message}"
128
- end
129
- end
130
-
131
- @deals.each do |deal|
132
- validation_message = deal.validate
133
-
134
- if !validation_message.empty?
135
- error = "#{error}\n#{validation_message}"
136
- end
137
- end
138
-
139
- return error.strip
140
- end
141
- end
142
- end
1
+ module FruitToLime
2
+ class RootModel
3
+ # the import_coworker is a special coworker that is set as
4
+ # responsible for objects that requires a coworker, eg a note.
5
+ attr_accessor :organizations, :coworkers, :deals, :notes, :import_coworker
6
+ def serialize_variables
7
+ [
8
+ {:id => :coworkers, :type => :coworkers},
9
+ {:id => :organizations, :type => :organizations},
10
+ {:id => :deals, :type => :deals},
11
+ {:id => :notes, :type => :notes},
12
+ ]
13
+ end
14
+
15
+ def serialize_name
16
+ "GoImport"
17
+ end
18
+
19
+ include SerializeHelper
20
+
21
+ def initialize()
22
+ @organizations = []
23
+ @coworkers = []
24
+ @import_coworker = Coworker.new
25
+ @import_coworker.integration_id = "import"
26
+ @import_coworker.first_name = "Import"
27
+ @coworkers.push @import_coworker
28
+ @deals = []
29
+ @notes = []
30
+ end
31
+
32
+ # Adds the specifed coworker object to the model.
33
+ def add_coworker(coworker)
34
+ @coworkers = [] if @coworkers == nil
35
+
36
+ if coworker != nil && coworker.is_a?(Coworker) && !@coworkers.include?(coworker)
37
+ @coworkers.push(coworker)
38
+ end
39
+ end
40
+
41
+ def add_note(text)
42
+ @notes = [] if @notes == nil
43
+ @notes.push(if text.is_a? Note then text else Note.new(text) end)
44
+ end
45
+
46
+ def with_note
47
+ @notes = [] if @notes == nil
48
+
49
+ note = Note.new
50
+ @notes.push note
51
+ yield note
52
+ end
53
+
54
+ # *** TODO:
55
+ #
56
+ # delete find_organization_by_reference and
57
+ #same_as_this_method from organization?
58
+ def find_organization_by_reference(organization_reference)
59
+ same_as_this = organization_reference.same_as_this_method
60
+ return @organizations.find do |org|
61
+ same_as_this.call(org)
62
+ end
63
+ end
64
+
65
+ def find_coworker_by_integration_id(integration_id)
66
+ return @coworkers.find do |coworker|
67
+ coworker == integration_id
68
+ end
69
+ end
70
+
71
+ def find_organization_by_integration_id(integration_id)
72
+ return @organizations.find do |organization|
73
+ organization == integration_id
74
+ end
75
+ end
76
+
77
+ def find_deals_for_organization(organization)
78
+ deals = []
79
+
80
+ deals = @deals.select do |deal|
81
+ !deal.customer.nil? && deal.customer.integration_id == organization.integration_id
82
+ end
83
+
84
+ return deals
85
+ end
86
+
87
+ def sanity_check
88
+ error = String.new
89
+
90
+ dups = get_duplicates(@coworkers) {|coworker| coworker.integration_id}
91
+ dups_error_items = (dups.collect{|coworker| coworker.integration_id}).compact
92
+ if dups.length > 0
93
+ error = "#{error}\nDuplicate coworker integration_id: #{dups_error_items.join(", ")}."
94
+ end
95
+
96
+ dups = get_duplicates(@organizations) {|org| org.integration_id}
97
+ dups_error_items = (dups.collect{|org| org.integration_id}).compact
98
+ if dups.length > 0
99
+ error = "#{error}\nDuplicate organization integration_id: #{dups_error_items.join(", ")}."
100
+ end
101
+
102
+ dups = get_duplicates(@deals) {|deal| deal.integration_id}
103
+ dups_error_items = (dups.collect{|deal| deal.integration_id}).compact
104
+ if dups_error_items.length > 0
105
+ error = "#{error}\nDuplicate deal integration_id: #{dups_error_items.join(", ")}."
106
+ end
107
+
108
+ return error.strip
109
+ end
110
+
111
+ # returns all items from the object array with duplicate keys.
112
+ # To get all organizations with the same integration_id use
113
+ # get_duplicates(organizations, {|org| org.integration_id})
114
+ def get_duplicates(objects, &key)
115
+ uniq_items = objects.uniq {|item| key.call(item)}.compact
116
+
117
+ return (objects - uniq_items).compact
118
+ end
119
+
120
+ def validate()
121
+ error = String.new
122
+
123
+ @organizations.each do |o|
124
+ validation_message = o.validate()
125
+
126
+ if !validation_message.empty?
127
+ error = "#{error}\n#{validation_message}"
128
+ end
129
+ end
130
+
131
+ @deals.each do |deal|
132
+ validation_message = deal.validate
133
+
134
+ if !validation_message.empty?
135
+ error = "#{error}\n#{validation_message}"
136
+ end
137
+ end
138
+
139
+ return error.strip
140
+ end
141
+ end
142
+ end
@@ -1,33 +1,33 @@
1
- # encoding: utf-8
2
- module FruitToLime
3
- class Tag
4
- def serialize_name
5
- "Tag"
6
- end
7
-
8
- attr_accessor :value
9
-
10
- def initialize(val=nil)
11
- if val
12
- @value = val
13
- end
14
- end
15
-
16
- def to_xml
17
- varn = serialize_name
18
- "<#{varn}>#{ @value.to_s.encode('utf-8').encode(:xml => :text) }</#{varn}>"
19
- end
20
-
21
- def to_s
22
- return "tag: '#{@value}'"
23
- end
24
-
25
- def ==(other)
26
- if other.respond_to?(:value)
27
- return @value == other.value
28
- else
29
- return false
30
- end
31
- end
32
- end
33
- end
1
+ # encoding: utf-8
2
+ module FruitToLime
3
+ class Tag
4
+ def serialize_name
5
+ "Tag"
6
+ end
7
+
8
+ attr_accessor :value
9
+
10
+ def initialize(val=nil)
11
+ if val
12
+ @value = val
13
+ end
14
+ end
15
+
16
+ def to_xml
17
+ varn = serialize_name
18
+ "<#{varn}>#{ @value.to_s.encode('utf-8').encode(:xml => :text) }</#{varn}>"
19
+ end
20
+
21
+ def to_s
22
+ return "tag: '#{@value}'"
23
+ end
24
+
25
+ def ==(other)
26
+ if other.respond_to?(:value)
27
+ return @value == other.value
28
+ else
29
+ return false
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,19 +1,19 @@
1
- module FruitToLime
2
- module ModelHasCustomFields
3
- # attr_reader :custom_fields
4
-
5
- #@custom_fields = []
6
-
7
- def set_custom_field(obj)
8
- @custom_fields = [] if @custom_fields==nil
9
- @custom_fields.push CustomField.new(obj)
10
- end
11
- end
12
-
13
- module ModelHasTags
14
- def add_tag(str)
15
- @tags = [] if @tags == nil
16
- @tags.push(Tag.new(str))
17
- end
18
- end
19
- end
1
+ module FruitToLime
2
+ module ModelHasCustomFields
3
+ # attr_reader :custom_fields
4
+
5
+ #@custom_fields = []
6
+
7
+ def set_custom_field(obj)
8
+ @custom_fields = [] if @custom_fields==nil
9
+ @custom_fields.push CustomField.new(obj)
10
+ end
11
+ end
12
+
13
+ module ModelHasTags
14
+ def add_tag(str)
15
+ @tags = [] if @tags == nil
16
+ @tags.push(Tag.new(str))
17
+ end
18
+ end
19
+ end