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.
Files changed (55) hide show
  1. data/lib/fruit_to_lime.rb +17 -17
  2. data/lib/fruit_to_lime/csv_helper.rb +47 -47
  3. data/lib/fruit_to_lime/email_helper.rb +10 -10
  4. data/lib/fruit_to_lime/errors.rb +16 -16
  5. data/lib/fruit_to_lime/excel_helper.rb +10 -10
  6. data/lib/fruit_to_lime/global_phone.json +6571 -6571
  7. data/lib/fruit_to_lime/model/address.rb +60 -60
  8. data/lib/fruit_to_lime/model/class_settings.rb +50 -50
  9. data/lib/fruit_to_lime/model/coworker.rb +76 -76
  10. data/lib/fruit_to_lime/model/coworker_reference.rb +33 -33
  11. data/lib/fruit_to_lime/model/customfield.rb +87 -87
  12. data/lib/fruit_to_lime/model/deal.rb +141 -141
  13. data/lib/fruit_to_lime/model/deal_status.rb +12 -12
  14. data/lib/fruit_to_lime/model/note.rb +80 -79
  15. data/lib/fruit_to_lime/model/organization.rb +203 -203
  16. data/lib/fruit_to_lime/model/person.rb +151 -151
  17. data/lib/fruit_to_lime/model/referencetosource.rb +45 -45
  18. data/lib/fruit_to_lime/model/relation.rb +23 -23
  19. data/lib/fruit_to_lime/model/rootmodel.rb +342 -338
  20. data/lib/fruit_to_lime/model/settings.rb +60 -60
  21. data/lib/fruit_to_lime/model/tag.rb +35 -35
  22. data/lib/fruit_to_lime/model_helpers.rb +54 -54
  23. data/lib/fruit_to_lime/phone_helper.rb +74 -74
  24. data/lib/fruit_to_lime/roo_helper.rb +72 -72
  25. data/lib/fruit_to_lime/serialize_helper.rb +186 -186
  26. data/lib/fruit_to_lime/templating.rb +52 -52
  27. data/spec/address_spec.rb +48 -48
  28. data/spec/class_settings_spec.rb +37 -37
  29. data/spec/coworker_spec.rb +94 -94
  30. data/spec/custom_field_spec.rb +22 -22
  31. data/spec/deal_spec.rb +101 -101
  32. data/spec/helpers/csv_helper_spec.rb +29 -29
  33. data/spec/helpers/email_helper_spec.rb +32 -32
  34. data/spec/helpers/phone_helper_spec.rb +97 -97
  35. data/spec/helpers/serialize_helper_spec.rb +249 -249
  36. data/spec/helpers/xsd_validate_spec.rb +58 -58
  37. data/spec/note_spec.rb +98 -98
  38. data/spec/organization_spec.rb +103 -103
  39. data/spec/person_spec.rb +134 -134
  40. data/spec/rootmodel_spec.rb +306 -277
  41. data/spec/templating_spec.rb +11 -11
  42. data/templates/csv/lib/tomodel.rb +230 -230
  43. data/templates/csv/spec/exporter_spec.rb +17 -17
  44. data/templates/csv/spec/sample_data/coworkers.csv +2 -2
  45. data/templates/csv/spec/sample_data/deals.csv +2 -2
  46. data/templates/csv/spec/sample_data/organizations.csv +2 -2
  47. data/templates/csv/spec/sample_data/persons.csv +2 -2
  48. data/templates/easy/Gemfile +5 -5
  49. data/templates/easy/Rakefile.rb +7 -7
  50. data/templates/easy/convert.rb +2 -2
  51. data/templates/easy/spec/exporter_spec.rb +10 -10
  52. data/templates/easy/spec/spec_helper.rb +24 -24
  53. data/templates/excel/lib/tomodel.rb +207 -207
  54. data/templates/sqlserver/lib/tomodel.rb +79 -79
  55. metadata +3 -3
@@ -1,61 +1,61 @@
1
- # encoding: utf-8
2
- module FruitToLime
3
- class Settings
4
- include SerializeHelper
5
- attr_reader :organization, :person, :deal
6
-
7
- # @example Add custom fields available for organization
8
- # rootmodel.settings.with_organization do |organization_settings|
9
- # organization_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
10
- # organization_settings.set_custom_field({:integration_id=>"yield_quota", :title=>"Yield quota"})
11
- # end
12
- # @see ClassSettings
13
- # @see CustomField
14
- # @see RootModel
15
- def with_organization
16
- @organization = ClassSettings.new if @organization ==nil
17
- yield @organization
18
- end
19
-
20
- # @example Add custom fields available for person
21
- # rootmodel.settings.with_person do |person_settings|
22
- # person_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
23
- # end
24
- # @see ClassSettings
25
- # @see CustomField
26
- # @see RootModel
27
- def with_person
28
- @person = ClassSettings.new if @person ==nil
29
- yield @person
30
- end
31
-
32
- # @example Add custom fields available for deal
33
- # rootmodel.settings.with_deal do |deal_settings|
34
- # deal_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
35
- # end
36
- # @see ClassSettings
37
- # @see CustomField
38
- # @see RootModel
39
- def with_deal
40
- @deal = ClassSettings.new if @deal ==nil
41
- yield @deal
42
- end
43
-
44
- def initialize(opt = nil)
45
- if opt != nil
46
- serialize_variables.each do |myattr|
47
- val = opt[myattr[:id]]
48
- instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
49
- end
50
- end
51
- end
52
-
53
- def serialize_variables
54
- [:organization, :person, :deal].map {|p| {:id => p, :type => :class_settings} }
55
- end
56
-
57
- def serialize_name
58
- "Settings"
59
- end
60
- end
1
+ # encoding: utf-8
2
+ module FruitToLime
3
+ class Settings
4
+ include SerializeHelper
5
+ attr_reader :organization, :person, :deal
6
+
7
+ # @example Add custom fields available for organization
8
+ # rootmodel.settings.with_organization do |organization_settings|
9
+ # organization_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
10
+ # organization_settings.set_custom_field({:integration_id=>"yield_quota", :title=>"Yield quota"})
11
+ # end
12
+ # @see ClassSettings
13
+ # @see CustomField
14
+ # @see RootModel
15
+ def with_organization
16
+ @organization = ClassSettings.new if @organization ==nil
17
+ yield @organization
18
+ end
19
+
20
+ # @example Add custom fields available for person
21
+ # rootmodel.settings.with_person do |person_settings|
22
+ # person_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
23
+ # end
24
+ # @see ClassSettings
25
+ # @see CustomField
26
+ # @see RootModel
27
+ def with_person
28
+ @person = ClassSettings.new if @person ==nil
29
+ yield @person
30
+ end
31
+
32
+ # @example Add custom fields available for deal
33
+ # rootmodel.settings.with_deal do |deal_settings|
34
+ # deal_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
35
+ # end
36
+ # @see ClassSettings
37
+ # @see CustomField
38
+ # @see RootModel
39
+ def with_deal
40
+ @deal = ClassSettings.new if @deal ==nil
41
+ yield @deal
42
+ end
43
+
44
+ def initialize(opt = nil)
45
+ if opt != nil
46
+ serialize_variables.each do |myattr|
47
+ val = opt[myattr[:id]]
48
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
49
+ end
50
+ end
51
+ end
52
+
53
+ def serialize_variables
54
+ [:organization, :person, :deal].map {|p| {:id => p, :type => :class_settings} }
55
+ end
56
+
57
+ def serialize_name
58
+ "Settings"
59
+ end
60
+ end
61
61
  end
@@ -1,35 +1,35 @@
1
- # encoding: utf-8
2
-
3
- module FruitToLime
4
- class Tag
5
- def serialize_name
6
- "Tag"
7
- end
8
-
9
- attr_accessor :value
10
-
11
- def initialize(val=nil)
12
- if val
13
- @value = val
14
- end
15
- end
16
-
17
- # @!visibility private
18
- def to_rexml(elem)
19
- element_name = serialize_name
20
- elem.add_element(element_name).text = @value.to_s.encode('utf-8')
21
- end
22
-
23
- def to_s
24
- return "tag: '#{@value}'"
25
- end
26
-
27
- def ==(other)
28
- if other.respond_to?(:value)
29
- return @value == other.value
30
- else
31
- return false
32
- end
33
- end
34
- end
35
- end
1
+ # encoding: utf-8
2
+
3
+ module FruitToLime
4
+ class Tag
5
+ def serialize_name
6
+ "Tag"
7
+ end
8
+
9
+ attr_accessor :value
10
+
11
+ def initialize(val=nil)
12
+ if val
13
+ @value = val
14
+ end
15
+ end
16
+
17
+ # @!visibility private
18
+ def to_rexml(elem)
19
+ element_name = serialize_name
20
+ elem.add_element(element_name).text = @value.to_s.encode('utf-8')
21
+ end
22
+
23
+ def to_s
24
+ return "tag: '#{@value}'"
25
+ end
26
+
27
+ def ==(other)
28
+ if other.respond_to?(:value)
29
+ return @value == other.value
30
+ else
31
+ return false
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,54 +1,54 @@
1
- module FruitToLime
2
- module ModelHasCustomFields
3
- # @example
4
- # value = row['business_value_partner_info']
5
- # obj.set_custom_value("partner_info", value)
6
- def set_custom_value(integration_id, value)
7
- return set_custom_field({integration_id: integration_id, value: value})
8
- end
9
- # @example
10
- # value = row['business_value_partner_info']
11
- # obj.set_custom_field({:integration_id=>"partner_info", :value=>value})
12
- def set_custom_field(obj)
13
- @custom_values = [] if @custom_values == nil
14
- value = obj[:value]
15
- field = CustomFieldReference.new(obj)
16
- custom_value = CustomValue.new
17
- custom_value.value = value
18
- custom_value.field = field
19
- index = @custom_values.find_index do |custom_value|
20
- custom_value.field.same_as?(field)
21
- end
22
- if index
23
- @custom_values.delete_at index
24
- end
25
-
26
- @custom_values.push custom_value
27
- return custom_value
28
- end
29
- end
30
-
31
- module ModelWithIntegrationIdSameAs
32
- # check if other is same as regarding integration_id or id
33
- def same_as?(other)
34
- if @integration_id!=nil && @integration_id == other.integration_id
35
- return true
36
- end
37
- if @id != nil && @id == other.id
38
- return true
39
- end
40
- return false
41
- end
42
- end
43
-
44
- module ModelHasTags
45
- # @example
46
- # obj.set_tag("partner")
47
- def set_tag(str)
48
- @tags = [] if @tags == nil
49
- if ! @tags.any? {|tag| tag.value == str }
50
- @tags.push(Tag.new(str))
51
- end
52
- end
53
- end
54
- end
1
+ module FruitToLime
2
+ module ModelHasCustomFields
3
+ # @example
4
+ # value = row['business_value_partner_info']
5
+ # obj.set_custom_value("partner_info", value)
6
+ def set_custom_value(integration_id, value)
7
+ return set_custom_field({integration_id: integration_id, value: value})
8
+ end
9
+ # @example
10
+ # value = row['business_value_partner_info']
11
+ # obj.set_custom_field({:integration_id=>"partner_info", :value=>value})
12
+ def set_custom_field(obj)
13
+ @custom_values = [] if @custom_values == nil
14
+ value = obj[:value]
15
+ field = CustomFieldReference.new(obj)
16
+ custom_value = CustomValue.new
17
+ custom_value.value = value
18
+ custom_value.field = field
19
+ index = @custom_values.find_index do |custom_value|
20
+ custom_value.field.same_as?(field)
21
+ end
22
+ if index
23
+ @custom_values.delete_at index
24
+ end
25
+
26
+ @custom_values.push custom_value
27
+ return custom_value
28
+ end
29
+ end
30
+
31
+ module ModelWithIntegrationIdSameAs
32
+ # check if other is same as regarding integration_id or id
33
+ def same_as?(other)
34
+ if @integration_id!=nil && @integration_id == other.integration_id
35
+ return true
36
+ end
37
+ if @id != nil && @id == other.id
38
+ return true
39
+ end
40
+ return false
41
+ end
42
+ end
43
+
44
+ module ModelHasTags
45
+ # @example
46
+ # obj.set_tag("partner")
47
+ def set_tag(str)
48
+ @tags = [] if @tags == nil
49
+ if ! @tags.any? {|tag| tag.value == str }
50
+ @tags.push(Tag.new(str))
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,74 +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
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