fruit_to_lime 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
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
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
- 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
+ #!/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
@@ -1,44 +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
+ 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,17 +1,17 @@
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
+ 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,30 +1,30 @@
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
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
@@ -1,38 +1,38 @@
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
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