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.
- data/bin/fruit_to_lime +24 -24
- data/lib/fruit_to_lime/address_helper.rb +17 -17
- data/lib/fruit_to_lime/csv_helper.rb +32 -32
- data/lib/fruit_to_lime/model/address.rb +37 -37
- data/lib/fruit_to_lime/model/coworker.rb +44 -0
- data/lib/fruit_to_lime/model/coworker_reference.rb +17 -14
- data/lib/fruit_to_lime/model/customfield.rb +30 -29
- data/lib/fruit_to_lime/model/deal.rb +49 -0
- data/lib/fruit_to_lime/model/note.rb +38 -27
- data/lib/fruit_to_lime/model/organization.rb +140 -121
- data/lib/fruit_to_lime/model/person.rb +115 -111
- data/lib/fruit_to_lime/model/referencetosource.rb +42 -42
- data/lib/fruit_to_lime/model/rootmodel.rb +142 -39
- data/lib/fruit_to_lime/model/tag.rb +33 -28
- data/lib/fruit_to_lime/model_helpers.rb +19 -0
- data/lib/fruit_to_lime/roo_helper.rb +59 -54
- data/lib/fruit_to_lime/serialize_helper.rb +139 -139
- data/lib/fruit_to_lime/templating.rb +51 -51
- data/lib/fruit_to_lime.rb +13 -12
- data/spec/helpers/address_helper_spec.rb +48 -48
- data/spec/helpers/csv_helper_spec.rb +15 -15
- data/spec/helpers/roo_helper_spec.rb +10 -10
- data/spec/helpers/serialize_helper_spec.rb +211 -211
- data/spec/person_spec.rb +44 -44
- data/spec/spec_helper.rb +24 -24
- data/spec/templating_spec.rb +40 -40
- data/templates/csv/Gemfile +5 -5
- data/templates/csv/Rakefile.rb +7 -7
- data/templates/csv/convert.rb +2 -2
- data/templates/csv/lib/tomodel.rb +56 -42
- data/templates/csv/spec/sample_data/organizations.csv +2 -2
- data/templates/csv/spec/spec_helper.rb +24 -24
- data/templates/csv/spec/tomodel_spec.rb +14 -14
- 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 +53 -39
- data/templates/excel/spec/spec_helper.rb +20 -20
- data/templates/excel/spec/tomodel_spec.rb +18 -18
- data/templates/sqlserver/Gemfile +6 -6
- data/templates/sqlserver/Rakefile.rb +7 -7
- data/templates/sqlserver/convert.rb +2 -2
- data/templates/sqlserver/lib/tomodel.rb +67 -53
- data/templates/sqlserver/spec/spec_helper.rb +20 -20
- data/templates/sqlserver/spec/tomodel_spec.rb +9 -9
- metadata +23 -4
data/bin/fruit_to_lime
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require "thor"
|
3
|
-
require "fruit_to_lime"
|
4
|
-
|
5
|
-
class Cli < Thor
|
6
|
-
desc "unpack_template NAME PATH", "Unpacks template with NAME in specified PATH or current directory if missing."
|
7
|
-
def unpack_template(name, path = nil)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
desc "list_templates", "Lists all templates"
|
16
|
-
def list_templates()
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
Cli.start(ARGV)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "thor"
|
3
|
+
require "fruit_to_lime"
|
4
|
+
|
5
|
+
class Cli < Thor
|
6
|
+
desc "unpack_template NAME PATH", "Unpacks template with NAME in specified PATH or current directory if missing."
|
7
|
+
def unpack_template(name, path = nil)
|
8
|
+
path = '.' if path == nil
|
9
|
+
path = File.absolute_path(path)
|
10
|
+
templates_path = File.expand_path("../templates", File.dirname(__FILE__))
|
11
|
+
templating = FruitToLime::Templating.new templates_path
|
12
|
+
templating.unpack(name, path)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "list_templates", "Lists all templates"
|
16
|
+
def list_templates()
|
17
|
+
templates_path = File.expand_path("../templates", File.dirname(__FILE__))
|
18
|
+
templating = FruitToLime::Templating.new templates_path
|
19
|
+
list_of_templates = templating.list
|
20
|
+
puts list_of_templates
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Cli.start(ARGV)
|
@@ -1,18 +1,18 @@
|
|
1
|
-
module FruitToLime
|
2
|
-
module AddressHelper
|
3
|
-
# parses a line like "226 48 LUND" into its corresponding
|
4
|
-
# zipcode and city properties on the address
|
5
|
-
def self.parse_line_to_zip_and_address_se(line, address)
|
6
|
-
matched_zipcode = /^\d{3}\s?\d{2}/.match(line)
|
7
|
-
if matched_zipcode && matched_zipcode.length == 1
|
8
|
-
address.zip_code = matched_zipcode[0].strip()
|
9
|
-
matched_city = /\D*$/.match(line)
|
10
|
-
if matched_city && matched_city.length == 1
|
11
|
-
address.city = matched_city[0].strip()
|
12
|
-
return address
|
13
|
-
end
|
14
|
-
end
|
15
|
-
return nil
|
16
|
-
end
|
17
|
-
end
|
1
|
+
module FruitToLime
|
2
|
+
module AddressHelper
|
3
|
+
# parses a line like "226 48 LUND" into its corresponding
|
4
|
+
# zipcode and city properties on the address
|
5
|
+
def self.parse_line_to_zip_and_address_se(line, address)
|
6
|
+
matched_zipcode = /^\d{3}\s?\d{2}/.match(line)
|
7
|
+
if matched_zipcode && matched_zipcode.length == 1
|
8
|
+
address.zip_code = matched_zipcode[0].strip()
|
9
|
+
matched_city = /\D*$/.match(line)
|
10
|
+
if matched_city && matched_city.length == 1
|
11
|
+
address.city = matched_city[0].strip()
|
12
|
+
return address
|
13
|
+
end
|
14
|
+
end
|
15
|
+
return nil
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
@@ -1,33 +1,33 @@
|
|
1
|
-
require "csv"
|
2
|
-
module FruitToLime
|
3
|
-
module CsvHelper
|
4
|
-
def self.detect_col_sep(text)
|
5
|
-
firstline = text.split('\n').first
|
6
|
-
col_seps = [';','\t',',']
|
7
|
-
return col_seps.find do |c|
|
8
|
-
firstline.include? c
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.text_to_hashes(text)
|
13
|
-
if !text
|
14
|
-
raise "Missing text"
|
15
|
-
end
|
16
|
-
rows = CSV.parse(text.strip,{:col_sep=>self.detect_col_sep(text)})
|
17
|
-
map = {}
|
18
|
-
first = rows.first
|
19
|
-
(0 .. first.length-1).each do |i|
|
20
|
-
map[i] = first[i]
|
21
|
-
end
|
22
|
-
rs = []
|
23
|
-
(1 .. rows.length-1).each do |i|
|
24
|
-
r={}
|
25
|
-
(0 .. map.length-1).each do |j|
|
26
|
-
r[map[j]] = rows[i][j]
|
27
|
-
end
|
28
|
-
rs.push(r)
|
29
|
-
end
|
30
|
-
return rs
|
31
|
-
end
|
32
|
-
end
|
1
|
+
require "csv"
|
2
|
+
module FruitToLime
|
3
|
+
module CsvHelper
|
4
|
+
def self.detect_col_sep(text)
|
5
|
+
firstline = text.split('\n').first
|
6
|
+
col_seps = [';','\t',',']
|
7
|
+
return col_seps.find do |c|
|
8
|
+
firstline.include? c
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.text_to_hashes(text)
|
13
|
+
if !text
|
14
|
+
raise "Missing text"
|
15
|
+
end
|
16
|
+
rows = CSV.parse(text.strip,{:col_sep=>self.detect_col_sep(text)})
|
17
|
+
map = {}
|
18
|
+
first = rows.first
|
19
|
+
(0 .. first.length-1).each do |i|
|
20
|
+
map[i] = first[i]
|
21
|
+
end
|
22
|
+
rs = []
|
23
|
+
(1 .. rows.length-1).each do |i|
|
24
|
+
r={}
|
25
|
+
(0 .. map.length-1).each do |j|
|
26
|
+
r[map[j]] = rows[i][j]
|
27
|
+
end
|
28
|
+
rs.push(r)
|
29
|
+
end
|
30
|
+
return rs
|
31
|
+
end
|
32
|
+
end
|
33
33
|
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
require 'iso_country_codes'
|
2
|
-
module FruitToLime
|
3
|
-
class Address
|
4
|
-
attr_accessor :street, :zip_code, :city, :country_code, :location
|
5
|
-
def serialize_variables
|
6
|
-
[ :street, :zip_code, :city, :country_code, :location].map {|p| {:id=>p,:type=>:string} }
|
7
|
-
end
|
8
|
-
include SerializeHelper
|
9
|
-
def initialize()
|
10
|
-
end
|
11
|
-
|
12
|
-
def get_import_rows
|
13
|
-
(serialize_variables+[{:id=>:country_name, :type=>:string}]).map do |p|
|
14
|
-
map_to_row p
|
15
|
-
end
|
16
|
-
end
|
17
|
-
def country_name
|
18
|
-
if @country_code
|
19
|
-
IsoCountryCodes.find(@country_code).name
|
20
|
-
else
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
def country_name=(name)
|
25
|
-
@country_code = case name
|
26
|
-
when nil
|
27
|
-
nil
|
28
|
-
when 'Sverige'
|
29
|
-
'SE'
|
30
|
-
else
|
31
|
-
IsoCountryCodes.search_by_name(name).first.alpha2
|
32
|
-
end
|
33
|
-
end
|
34
|
-
def parse_zip_and_address_se(line)
|
35
|
-
FruitToLime::AddressHelper::parse_line_to_zip_and_address_se(line, self)
|
36
|
-
end
|
37
|
-
end
|
1
|
+
require 'iso_country_codes'
|
2
|
+
module FruitToLime
|
3
|
+
class Address
|
4
|
+
attr_accessor :street, :zip_code, :city, :country_code, :location
|
5
|
+
def serialize_variables
|
6
|
+
[ :street, :zip_code, :city, :country_code, :location].map {|p| {:id=>p,:type=>:string} }
|
7
|
+
end
|
8
|
+
include SerializeHelper
|
9
|
+
def initialize()
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_import_rows
|
13
|
+
(serialize_variables+[{:id=>:country_name, :type=>:string}]).map do |p|
|
14
|
+
map_to_row p
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def country_name
|
18
|
+
if @country_code
|
19
|
+
IsoCountryCodes.find(@country_code).name
|
20
|
+
else
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
def country_name=(name)
|
25
|
+
@country_code = case name
|
26
|
+
when nil
|
27
|
+
nil
|
28
|
+
when 'Sverige'
|
29
|
+
'SE'
|
30
|
+
else
|
31
|
+
IsoCountryCodes.search_by_name(name).first.alpha2
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def parse_zip_and_address_se(line)
|
35
|
+
FruitToLime::AddressHelper::parse_line_to_zip_and_address_se(line, self)
|
36
|
+
end
|
37
|
+
end
|
38
38
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module FruitToLime
|
2
|
+
class Coworker
|
3
|
+
include SerializeHelper
|
4
|
+
attr_accessor :id, :integration_id, :first_name, :last_name, :email, :direct_phone_number,
|
5
|
+
:mobile_phone_number, :home_phone_number
|
6
|
+
|
7
|
+
def initialize()
|
8
|
+
end
|
9
|
+
|
10
|
+
def serialize_variables
|
11
|
+
[
|
12
|
+
:id, :integration_id, :first_name, :last_name, :email,
|
13
|
+
:direct_phone_number, :mobile_phone_number, :home_phone_number
|
14
|
+
].map {|p| { :id => p, :type => :string } }
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_reference
|
18
|
+
reference = CoworkerReference.new
|
19
|
+
reference.id = @id
|
20
|
+
reference.integration_id = @integration_id
|
21
|
+
reference.heading = "#{@first_name} #{@last_name}".strip
|
22
|
+
|
23
|
+
return reference
|
24
|
+
end
|
25
|
+
|
26
|
+
def serialize_name
|
27
|
+
"Coworker"
|
28
|
+
end
|
29
|
+
|
30
|
+
def ==(that)
|
31
|
+
if that.nil?
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
|
35
|
+
if that.is_a? Coworker
|
36
|
+
return @integration_id == that.integration_id
|
37
|
+
elsif that.is_a? String
|
38
|
+
return @integration_id == that
|
39
|
+
end
|
40
|
+
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,14 +1,17 @@
|
|
1
|
-
module FruitToLime
|
2
|
-
class CoworkerReference
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
module FruitToLime
|
2
|
+
class CoworkerReference
|
3
|
+
include SerializeHelper
|
4
|
+
attr_accessor :id, :heading, :integration_id
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
end
|
8
|
+
|
9
|
+
def serialize_variables
|
10
|
+
[:id, :heading, :integration_id].map {|p| {:id => p, :type => :string} }
|
11
|
+
end
|
12
|
+
|
13
|
+
def serialize_name
|
14
|
+
"CoworkerReference"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,29 +1,30 @@
|
|
1
|
-
module FruitToLime
|
2
|
-
class CustomField
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
1
|
+
module FruitToLime
|
2
|
+
class CustomField
|
3
|
+
include SerializeHelper
|
4
|
+
|
5
|
+
attr_accessor :id, :integration_id, :title, :value
|
6
|
+
|
7
|
+
def initialize(opt=nil)
|
8
|
+
if opt != nil
|
9
|
+
serialize_variables.each do |myattr|
|
10
|
+
val = opt[myattr[:id]]
|
11
|
+
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def serialize_variables
|
17
|
+
[:id, :integration_id, :title, :value].map {|p| { :id => p, :type => :string } }
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_import_rows
|
21
|
+
serialize_variables.map do |p|
|
22
|
+
map_to_row p
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def serialize_name
|
27
|
+
"CustomField"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
module FruitToLime
|
3
|
+
class Deal
|
4
|
+
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
5
|
+
|
6
|
+
attr_accessor :id, :integration_id, :name, :description, :probability, :value, :order_date, :offer_date, :customer,
|
7
|
+
:responsible_coworker, :customer_contact
|
8
|
+
|
9
|
+
attr_reader :custom_fields
|
10
|
+
|
11
|
+
def serialize_variables
|
12
|
+
[ :id, :integration_id, :name, :description, :probability, :value, :offer_date, :order_date ].map {
|
13
|
+
|p| {
|
14
|
+
:id => p,
|
15
|
+
:type => :string
|
16
|
+
}
|
17
|
+
} +
|
18
|
+
[
|
19
|
+
{ :id => :customer, :type => :organization_reference },
|
20
|
+
{ :id => :responsible_coworker, :type => :coworker_reference },
|
21
|
+
{ :id => :customer_contact, :type => :person_reference },
|
22
|
+
{ :id => :custom_fields, :type => :custom_fields },
|
23
|
+
{ :id => :tags, :type => :tags }
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
def serialize_name
|
28
|
+
"Deal"
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize()
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
return "deal[id=#{@id}, integration_id=#{@integration_id}]"
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate
|
39
|
+
error = String.new
|
40
|
+
|
41
|
+
if @name.nil? || @name.empty?
|
42
|
+
error = "A name is required for deal.\n#{serialize()}"
|
43
|
+
end
|
44
|
+
|
45
|
+
return error
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -1,27 +1,38 @@
|
|
1
|
-
module FruitToLime
|
2
|
-
class Note
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
1
|
+
module FruitToLime
|
2
|
+
class Note
|
3
|
+
include SerializeHelper
|
4
|
+
attr_accessor :id, :text, :integration_id, :classification, :date, :created_by, :organization, :person
|
5
|
+
|
6
|
+
def serialize_variables
|
7
|
+
[ :id, :text, :integration_id, :classification ].map {
|
8
|
+
|p| {
|
9
|
+
:id => p,
|
10
|
+
:type => :string
|
11
|
+
}
|
12
|
+
} +
|
13
|
+
[
|
14
|
+
{ :id => :date, :type => :date },
|
15
|
+
{ :id => :created_by, :type => :coworker_reference },
|
16
|
+
{ :id => :organization, :type => :organization_reference },
|
17
|
+
{ :id => :person, :type => :person_reference }
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_import_rows
|
22
|
+
(serialize_variables+[
|
23
|
+
{:id=>:organization, :type=>:organization_reference},
|
24
|
+
{:id=>:person, :type=>:person_reference}
|
25
|
+
]).map do |p|
|
26
|
+
map_to_row p
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def serialize_name
|
31
|
+
"Note"
|
32
|
+
end
|
33
|
+
|
34
|
+
# def with_organization
|
35
|
+
# yield org
|
36
|
+
# end
|
37
|
+
end
|
38
|
+
end
|