fruit_to_lime 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fruit_to_lime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-19 00:00:00.000000000 Z
12
+ date: 2013-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iso_country_codes
@@ -80,13 +80,11 @@ files:
80
80
  - lib/fruit_to_lime/model/rootmodel.rb
81
81
  - lib/fruit_to_lime/model/sourceref.rb
82
82
  - lib/fruit_to_lime/model/tag.rb
83
- - lib/fruit_to_lime/serialize_helper.rb
84
83
  - lib/fruit_to_lime.rb
85
84
  - spec/gosourceref_spec.rb
86
85
  - spec/helpers/address_helper_spec.rb
87
86
  - spec/helpers/csv_helper_spec.rb
88
87
  - spec/helpers/serialize_helper_spec.rb
89
- - spec/organization_spec.rb
90
88
  - spec/person_spec.rb
91
89
  - spec/spec_helper.rb
92
90
  homepage:
@@ -118,6 +116,5 @@ test_files:
118
116
  - spec/helpers/address_helper_spec.rb
119
117
  - spec/helpers/csv_helper_spec.rb
120
118
  - spec/helpers/serialize_helper_spec.rb
121
- - spec/organization_spec.rb
122
119
  - spec/person_spec.rb
123
120
  - spec/spec_helper.rb
@@ -1,207 +0,0 @@
1
- module FruitToLime
2
- module SerializeHelper
3
-
4
- def fill_using(entity_columns, row)
5
- entity_columns.select do |ecol|
6
- ecol.selected!=nil && ecol.selected.length >0 && ecol.column!=nil && ecol.column.length > 0
7
- end.each do |ecol|
8
- selected = ecol.selected
9
- value = row[ecol.column]
10
- set_attribute(selected, value)
11
- end
12
- return self
13
- end
14
-
15
- def serialize()
16
- SerializeHelper::serialize(self)
17
- end
18
-
19
- def serialize_to_file(file)
20
- SerializeHelper::serialize_to_file(file, self)
21
- end
22
-
23
- def self.serialize_variables(obj)
24
- if (obj.respond_to?(:serialize_variables))
25
- return obj.serialize_variables.map do |ivar|
26
- varn = ivar[:id].to_s.gsub(/^\@/,'').split('_').map do |m|
27
- m.capitalize
28
- end.join('')
29
- varv = obj.instance_variable_get("@#{ivar[:id].to_s}")
30
- if (varv.respond_to?(:serialize_variables))
31
- varv = serialize_variables(varv)
32
- elsif (varv.is_a?(Array))
33
- varv = varv.map { |elem| SerializeHelper::serialize(elem) }.join("\n")
34
- else
35
- varv = varv.to_s.encode(:xml => :text)
36
- end
37
- "<#{varn}>#{ varv }</#{varn}>"
38
- end.join("\n")
39
- end
40
- raise "!!#{obj.class}"
41
- end
42
-
43
- def self.serialize(obj)
44
- if (obj.respond_to?(:serialize_variables))
45
- varn = obj.serialize_name
46
- "<#{varn}>#{ SerializeHelper::serialize_variables(obj) }</#{varn}>"
47
- elsif obj.respond_to?(:to_xml)
48
- obj.to_xml
49
- else
50
- obj.to_s.encode(:xml => :text)
51
- end
52
- end
53
-
54
- def self.serialize_to_file(file, obj)
55
- File.open(file, 'w') do |f|
56
- f.write(SerializeHelper::serialize(obj))
57
- end
58
- end
59
-
60
- def set_attribute(selected, value)
61
- if selected.is_a? String
62
- selected = [selected]
63
- end
64
- case selected.length
65
- when 1
66
- found = get_import_rows.find do |v|
67
- v[:id].to_s == selected.first
68
- end
69
- if !found
70
- return false
71
- end
72
- send(found[:id].to_s+"=",value)
73
- return true
74
- when 2
75
- found = get_import_rows.find do |v|
76
- v[:id].to_s == selected.first
77
- end
78
- if !found
79
- return false
80
- end
81
- subval = send(found[:id].to_s)
82
- if !subval
83
- subval = get_default(found[:type])
84
- send(found[:id].to_s+"=",subval)
85
- end
86
- subval.set_attribute(selected.slice(1), value)
87
- else
88
- raise "! #{selected.length}"
89
- end
90
- end
91
-
92
- def symbol_to_name(symbol)
93
- symbol.to_s.split('_').join(' ').capitalize
94
- end
95
-
96
- def get_default(type)
97
- case type
98
- when :string then
99
- ""
100
- when :bool then
101
- false
102
- when :source_ref then
103
- SourceRef.new
104
- when :address then
105
- Address.new
106
- when :notes then
107
- []
108
- when :tags then
109
- []
110
- when :persons then
111
- []
112
- when :custom_fields then
113
- []
114
- when :organization_reference then
115
- OrganizationReference.new
116
- when :date then
117
- nil
118
- when :coworker_reference then
119
- CoworkerReference.new
120
- else
121
- raise "Dont know how to handle '#{type}'"
122
- end
123
- end
124
-
125
- def map_symbol_to_row(symbol,type)
126
- {
127
- :id=>symbol.to_s,
128
- :name=> symbol==:id ? 'Go id' : symbol_to_name(symbol),
129
- :type=>type
130
- }
131
- end
132
-
133
- def map_to_row(p)
134
- case p[:type]
135
- when :string then
136
- map_symbol_to_row(p[:id],p[:type])
137
- when :bool then
138
- map_symbol_to_row(p[:id],p[:type])
139
- when :date then
140
- map_symbol_to_row(p[:id],p[:type])
141
- when :notes then
142
- {
143
- :id => p[:id].to_s,
144
- :name => symbol_to_name(p[:id]),
145
- :type => p[:type],
146
- :models => SerializeHelper.get_import_rows(:note)
147
- }
148
- when :tags then
149
- {
150
- :id => p[:id].to_s,
151
- :type => p[:type],
152
- :name => symbol_to_name(p[:id]),
153
- }
154
- when :persons then
155
- {
156
- :id => p[:id].to_s,
157
- :type => p[:type],
158
- :name => symbol_to_name(p[:id]),
159
- :models => SerializeHelper.get_import_rows(:person)
160
- }
161
- when :custom_fields then
162
- {
163
- :id => p[:id].to_s,
164
- :type => p[:type],
165
- :name => symbol_to_name(p[:id]),
166
- :models => SerializeHelper.get_import_rows(:custom_field)
167
- }
168
- else
169
- {
170
- :id => p[:id].to_s,
171
- :name => symbol_to_name(p[:id]),
172
- :type => p[:type],
173
- :model => SerializeHelper.get_import_rows(p[:type])
174
- }
175
- end
176
- end
177
-
178
- def get_import_rows
179
- serialize_variables.map do |p|
180
- map_to_row p
181
- end
182
- end
183
-
184
- def self.get_import_rows(type)
185
- case type
186
- when :person then
187
- Person.new
188
- when :source_ref then
189
- SourceRef.new
190
- when :note then
191
- Note.new
192
- when :address then
193
- Address.new
194
- when :organization then
195
- Organization.new
196
- when :coworker_reference then
197
- CoworkerReference.new
198
- when :organization_reference then
199
- OrganizationReference.new
200
- when :custom_field then
201
- CustomField.new
202
- else
203
- raise "Unknown type: #{type}"
204
- end.get_import_rows
205
- end
206
- end
207
- end
@@ -1,16 +0,0 @@
1
- require "spec_helper"
2
- require 'fruit_to_lime'
3
-
4
- describe "Organization" do
5
- before (:all) do
6
- @organization = FruitToLime::Organization.new
7
- end
8
- it "can set a customfield" do
9
- @organization.set_custom_field('the key', 'the title', 'the value')
10
-
11
- field = @organization.custom_fields[0]
12
- field.integration_id.should eq 'the key'
13
- field.title.should eq 'the title'
14
- field.value.should eq 'the value'
15
- end
16
- end