fruit_to_lime 0.6.7 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/fruit_to_lime ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ require "thor"
3
+ require "fileutils"
4
+
5
+ class Templating
6
+ def initialize(path = nil)
7
+ if path == nil
8
+ path = File.expand_path("../templates", File.dirname(__FILE__))
9
+ end
10
+ @path = path
11
+ end
12
+
13
+ def list()
14
+ Dir.entries(@path).select { |d| d != '.' && d != '..' }
15
+ end
16
+
17
+ def unpack(name, path)
18
+ template = list.find { |t| t == name }
19
+ if template
20
+ puts "Unpacking template #{name} to #{path}"
21
+
22
+ FileUtils.cp_r File.expand_path(name, @path), path
23
+
24
+ true
25
+ else
26
+ puts "Unable to find template #{name}"
27
+ false
28
+ end
29
+ end
30
+ end
31
+
32
+ class Cli < Thor
33
+ desc "unpack_template NAME PATH", "Unpacks template with NAME in specified PATH or current directory if missing."
34
+ def unpack_template(name, path = nil)
35
+ path = '.' if path == nil
36
+ path = File.absolute_path(path)
37
+ Templating.new.unpack(name, path)
38
+ end
39
+
40
+ desc "list_templates", "Lists all templates"
41
+ def list_templates()
42
+ templates = Templating.new.list
43
+ puts templates
44
+ end
45
+ end
46
+
47
+ Cli.start(ARGV)
@@ -8,22 +8,6 @@ module FruitToLime
8
8
  firstline.include? c
9
9
  end
10
10
  end
11
- # todo: http://ruby-doc.org/stdlib-1.9.3/libdoc/csv/rdoc/CSV.html
12
- # might be possible to simplify code using the headers option, etc
13
- def self.read_columns_and_first_five_lines(text)
14
- if !text
15
- raise "Missing text"
16
- end
17
- rows = CSV.parse(text.strip,{:col_sep=>self.detect_col_sep(text)})
18
- first = rows.first
19
- first_five_lines = rows[1,5]
20
- retval = []
21
- (0 .. first.length-1).each do |i|
22
- val = yield first[i], first_five_lines.map {|l| l[i] }
23
- retval.push(val)
24
- end
25
- return retval
26
- end
27
11
 
28
12
  def self.text_to_hashes(text)
29
13
  if !text
@@ -36,11 +36,12 @@ module FruitToLime
36
36
  class Organization < OrganizationReference
37
37
  include SerializeHelper
38
38
 
39
- attr_accessor :organization_number, :email, :web_site, :postal_address, :visit_address
39
+ attr_accessor :organization_number, :email, :web_site, :external_link, :postal_address, :visit_address
40
40
  attr_reader :employees, :notes, :custom_fields
41
41
 
42
42
  def initialize()
43
43
  end
44
+
44
45
  def with_postal_address
45
46
  @postal_address = Address.new
46
47
  yield @postal_address
@@ -55,17 +56,13 @@ module FruitToLime
55
56
  @custom_fields = [] if @custom_fields==nil
56
57
  @custom_fields.push CustomField.new(obj)
57
58
  end
58
- def source_ref
59
- @source_ref
60
- end
61
- def source_ref=(val)
62
- if !val.is_a? SourceRef
63
- @source_ref = SourceRef.new(val)
64
- else
65
- @source_ref = val
66
- end
59
+
60
+ def with_source
61
+ @source = ReferenceToSource.new
62
+ yield @source
67
63
  end
68
64
 
65
+
69
66
  def add_employee(val)
70
67
  @employees = [] if @employees==nil
71
68
  @employees.push(if val.is_a? Person then val else Person.new(val) end)
@@ -81,14 +78,14 @@ module FruitToLime
81
78
  end
82
79
 
83
80
  def serialize_variables
84
- [ :id, :integration_id, :name, :organization_number, :email, :web_site ].map { |prop| { :id => prop, :type => :string } } +
81
+ [ :id, :integration_id, :name, :organization_number, :external_link, :email, :web_site ].map { |prop| { :id => prop, :type => :string } } +
85
82
  [
86
83
  { :id => :postal_address, :type => :address},
87
84
  { :id => :visit_address, :type => :address},
88
85
  { :id => :employees, :type => :persons},
89
86
  { :id => :tags, :type => :tags},
90
87
  { :id => :custom_fields, :type => :custom_fields},
91
- { :id => :source_ref, :type => :source_ref}
88
+ { :id => :source, :type => :source_ref}
92
89
  ]
93
90
  end
94
91
 
@@ -55,17 +55,11 @@ module FruitToLime
55
55
  @custom_fields = [] if @custom_fields==nil
56
56
  @custom_fields.push CustomField.new(obj)
57
57
  end
58
- def source_ref
59
- @source_ref
60
- end
61
- def source_ref=(val)
62
- if !val.is_a? SourceRef
63
- @source_ref = SourceRef.new(val)
64
- else
65
- @source_ref = val
66
- end
67
- end
68
58
 
59
+ def with_source
60
+ @source = ReferenceToSource.new
61
+ yield @source
62
+ end
69
63
 
70
64
  def tags
71
65
  @tags
@@ -89,7 +83,7 @@ module FruitToLime
89
83
  #{:id=>:notes,:type=>:notes},
90
84
  {:id=>:tags,:type=>:tags},
91
85
  {:id=>:custom_fields,:type=>:custom_fields},
92
- {:id=>:source_ref,:type=>:source_ref}
86
+ {:id=>:source, :type=> :source_ref}
93
87
  ]
94
88
  end
95
89
 
@@ -0,0 +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
43
+ end
@@ -2,17 +2,6 @@
2
2
  module FruitToLime
3
3
  module SerializeHelper
4
4
 
5
- def fill_using(entity_columns, row)# TODO: Move to InCSV
6
- entity_columns.select do |ecol|
7
- ecol.selected!=nil && ecol.selected.length >0 && ecol.column!=nil && ecol.column.length > 0
8
- end.each do |ecol|
9
- selected = ecol.selected
10
- value = row[ecol.column]
11
- set_attribute(selected, value)
12
- end
13
- return self
14
- end
15
-
16
5
  def serialize()
17
6
  SerializeHelper::serialize(self)
18
7
  end
@@ -60,38 +49,6 @@ module SerializeHelper
60
49
  end
61
50
  end
62
51
 
63
- def set_attribute(selected, value)# TODO: Move to InCSV
64
- if selected.is_a? String
65
- selected = [selected]
66
- end
67
- case selected.length
68
- when 1
69
- found = get_import_rows.find do |v|
70
- v[:id].to_s == selected.first
71
- end
72
- if !found
73
- return false
74
- end
75
- send(found[:id].to_s+"=",value)
76
- return true
77
- when 2
78
- found = get_import_rows.find do |v|
79
- v[:id].to_s == selected.first
80
- end
81
- if !found
82
- return false
83
- end
84
- subval = send(found[:id].to_s)
85
- if !subval
86
- subval = nil
87
- send(found[:id].to_s+"=",subval)
88
- end
89
- subval.set_attribute(selected.slice(1), value)
90
- else
91
- raise "! #{selected.length}"
92
- end
93
- end
94
-
95
52
  def symbol_to_name(symbol)
96
53
  symbol.to_s.split('_').join(' ').capitalize
97
54
  end
@@ -160,7 +117,7 @@ module SerializeHelper
160
117
  when :person then
161
118
  Person.new
162
119
  when :source_ref then
163
- SourceRef.new
120
+ ReferenceToSource.new
164
121
  when :note then
165
122
  Note.new
166
123
  when :address then
data/lib/fruit_to_lime.rb CHANGED
@@ -7,6 +7,5 @@ module FruitToLime
7
7
  require 'fruit_to_lime/address_helper'
8
8
  FruitToLime::require_all_in 'fruit_to_lime/model/*.rb'
9
9
  require 'fruit_to_lime/csv_helper'
10
- require 'fruit_to_lime/column'
11
10
  require 'fruit_to_lime/roo_helper'
12
11
  end
@@ -1,63 +1,15 @@
1
1
  require 'spec_helper'
2
2
  require 'fruit_to_lime'
3
- # Specs in this file have access to a helper object that includes
4
- # the CsvHelper. For example:
5
- #
6
- # describe CsvHelper do
7
- # describe "string concat" do
8
- # it "concats two strings with spaces" do
9
- # helper.concat_strings("this","that").should == "this that"
10
- # end
11
- # end
12
- # end
13
- describe FruitToLime::CsvHelper do
14
- def text_to_model(text)
15
- FruitToLime::CsvHelper.read_columns_and_first_five_lines(text) do |column, first_five_lines|
16
- {:name=>column,:sample_data=>first_five_lines}
17
- end
18
- end
19
- #pending "add some examples to (or delete) #{__FILE__}"
20
- describe "from file to model" do
21
- it "should contain column name and sample_data" do
22
- v = text_to_model(
23
- "id;navn
24
- 1;Noerrebro
25
- 2;Roedoevre")
26
- v.should include({:name=>'id',:sample_data=>['1','2']})
27
- v.should include({:name=>'navn',:sample_data=>['Noerrebro','Roedoevre']})
28
- end
29
- it "should handle empty line" do
30
- v = text_to_model(
31
- "id;navn
32
- 1;Noerrebro
33
- "
34
- )
35
-
36
- expect(v).to eq([{:name=>'id',:sample_data=>['1']},
37
- {:name=>'navn',:sample_data=>['Noerrebro']}])
38
- end
39
- it "should limit to max 5 elements in sample_data" do
40
- v = text_to_model(
41
- "id;navn
42
- 1;Noerrebro
43
- 2;Roedoevre
44
- 3;Vesterbro
45
- 4;Roskilde
46
- 5;Taarnby
47
- 6;Naestved
48
- 7;Fredericia")
49
- v.should include({:name=>'id',:sample_data=>(1..5).map {|i| i.to_s }})
50
- end
51
3
 
52
- it "should" do
53
- v = FruitToLime::CsvHelper.text_to_hashes("id;navn
4
+ describe FruitToLime::CsvHelper do
5
+ it "should" do
6
+ v = FruitToLime::CsvHelper.text_to_hashes("id;navn
54
7
  1;Noerrebro")
55
- v.should include({"id"=>"1","navn"=>"Noerrebro"})
56
- end
57
- it "should handle sv chars" do
58
- v = FruitToLime::CsvHelper.text_to_hashes("id;navn
8
+ v.should include({"id"=>"1","navn"=>"Noerrebro"})
9
+ end
10
+ it "should handle sv chars" do
11
+ v = FruitToLime::CsvHelper.text_to_hashes("id;navn
59
12
  1;Bj\u{00F6}rk")
60
- v.should include({"id"=>"1","navn"=>"Bj\u{00F6}rk"})
61
- end
13
+ v.should include({"id"=>"1","navn"=>"Bj\u{00F6}rk"})
62
14
  end
63
15
  end
@@ -43,7 +43,10 @@ describe FruitToLime::SerializeHelper do
43
43
  p.id = "1"
44
44
  p.first_name = "Kalle"
45
45
  p.last_name = "Anka"
46
- p.source_ref = {:name=>'Go',:id=>"PASE122345"}
46
+ p.with_source do |source|
47
+ source.par_se('122345')
48
+ end
49
+ #p.source_ref = {:name=>'Go',:id=>"PASE122345"}
47
50
  p.with_postal_address do |addr|
48
51
  addr.city = "Ankeborg"
49
52
  end
@@ -67,8 +70,7 @@ describe FruitToLime::SerializeHelper do
67
70
  serialized.should match(/cf title/)
68
71
  serialized.should match(/cf value/)
69
72
  end
70
- it "should contain source ref" do
71
- serialized.should match(/PASE/)
73
+ it "should contain reference to source" do
72
74
  serialized.should match(/122345/)
73
75
  end
74
76
  it "should handle sv chars in tags" do
@@ -85,7 +87,10 @@ describe FruitToLime::SerializeHelper do
85
87
  let(:serialized) {
86
88
  o = FruitToLime::Organization.new
87
89
  o.name = "Ankeborgs bibliotek"
88
- o.source_ref = {:name=>'Go',:id=>"PASE122345"}
90
+ o.with_source do |source|
91
+ source.par_se('122345')
92
+ end
93
+ #o.source_ref = {:name=>'Go',:id=>"PASE122345"}
89
94
  o.add_tag("tag:bibliotek")
90
95
  o.add_tag("tag:Bj\u{00F6}rk")
91
96
  o.set_custom_field({:id=>"2", :title=>"cf title", :value=>"cf value"})
@@ -122,8 +127,7 @@ describe FruitToLime::SerializeHelper do
122
127
  serialized.should match(/cf value/)
123
128
  #puts serialized
124
129
  end
125
- it "should contain source ref" do
126
- serialized.should match(/PASE/)
130
+ it "should contain reference to source" do
127
131
  serialized.should match(/122345/)
128
132
  end
129
133
  it "should handle sv chars in tags" do
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'thor'
4
+ gem 'fruit_to_lime'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,3 @@
1
+ require "./lib/tomodel"
2
+
3
+ Cli.start(ARGV)
@@ -0,0 +1,42 @@
1
+ require 'fruit_to_lime'
2
+
3
+ class ToModel
4
+ def to_organization(row)
5
+ organization = FruitToLime::Organization.new
6
+ organization.integration_id = row['id']
7
+ organization.name = row['name']
8
+ return organization
9
+ end
10
+
11
+ def to_model(organization_file_name)
12
+ rootmodel = FruitToLime::RootModel.new
13
+ if organization_file_name != nil
14
+ organization_file_data = File.open(organization_file_name, 'r').read.encode('UTF-8',"ISO-8859-1")
15
+ rows = FruitToLime::CsvHelper::text_to_hashes(organization_file_data)
16
+ rows.each do |row|
17
+ rootmodel.organizations.push(to_organization(row))
18
+ end
19
+ end
20
+ return rootmodel
21
+ end
22
+
23
+ def save_xml(file)
24
+ File.open(file,'w') do |f|
25
+ f.write(FruitToLime::SerializeHelper::serialize(to_xml_model))
26
+ end
27
+ end
28
+ end
29
+
30
+ require "thor"
31
+ require "fileutils"
32
+ require 'pathname'
33
+
34
+ class Cli < Thor
35
+ desc "to_go ORGANIZATIONS FILE", "Exports xml to FILE using for ORGANIZATIONS csv file."
36
+ def to_go(organizations, file = nil)
37
+ file = 'export.xml' if file == nil
38
+ toModel = ToModel.new()
39
+ model = toModel.to_model(organizations)
40
+ model.serialize_to_file(file)
41
+ end
42
+ end
@@ -0,0 +1,2 @@
1
+ id;name;
2
+ 6;Alfs Mjukvaruutveckling
@@ -0,0 +1,24 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ #require File.expand_path("../../config/environment", __FILE__)
3
+ #require 'rspec/rails'
4
+ require 'rspec/autorun'
5
+
6
+ # Requires supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ #Dir[File.join(File.dirname(File.absolute_path(__FILE__)),"support/**/*.rb")].each { |f| require f }
9
+
10
+ RSpec.configure do |config|
11
+ # ## Mock Framework
12
+ #
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ #
15
+ # config.mock_with :mocha
16
+ # config.mock_with :flexmock
17
+ # config.mock_with :rr
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ config.order = "random"
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'tomodel'
3
+
4
+ describe 'ToModel' do
5
+ before(:all) do
6
+ toModel = ToModel.new
7
+ organizations_file =File.join(File.dirname(__FILE__), 'sample_data', 'organizations.csv')
8
+ @model = toModel.to_model(organizations_file, persons_file)
9
+ end
10
+ it "will find something with a name" do
11
+ organization = @model.organizations[0]
12
+ organization.name.length.should > 0
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'roo'
4
+ gem 'thor'
5
+ gem 'fruit_to_lime'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,3 @@
1
+ require "./lib/tomodel"
2
+
3
+ Cli.start(ARGV)
@@ -0,0 +1,39 @@
1
+ require 'fruit_to_lime'
2
+ require 'roo'
3
+
4
+ class ToModel
5
+ def to_organization(row)
6
+ organization = FruitToLime::Organization.new()
7
+ # Map properties
8
+ organization.integration_id = row['Id']
9
+ organization.name = row['Name']
10
+
11
+ return organization
12
+ end
13
+
14
+ def to_model(organization_file_name)
15
+ # from excel to csv
16
+ organization_file_data = Roo::Excelx.new(organization_file_name)
17
+
18
+ model = FruitToLime::RootModel.new
19
+ rows = FruitToLime::RooHelper.new(organization_file_data).rows
20
+ rows.each do |row|
21
+ model.organizations.push(to_organization(row))
22
+ end
23
+ return model
24
+ end
25
+ end
26
+
27
+ require "thor"
28
+ require "fileutils"
29
+ require 'pathname'
30
+
31
+ class Cli < Thor
32
+ desc "to_go ORGANIZATION FILE", "Converts excel file to Go xml format. ORGANIZATIONS is path to input file. FILE is output file where Go xml will go."
33
+ def to_go(organizations, file = nil)
34
+ file = 'export.xml' if file == nil
35
+ scala = ScalaToModel.new()
36
+ model = scala.to_model(organizations)
37
+ model.serialize_to_file(file)
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ #require File.expand_path("../../config/environment", __FILE__)
3
+ require 'rspec/autorun'
4
+
5
+ RSpec.configure do |config|
6
+ # ## Mock Framework
7
+ #
8
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
9
+ #
10
+ # config.mock_with :mocha
11
+ # config.mock_with :flexmock
12
+ # config.mock_with :rr
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = "random"
19
+ end
20
+
@@ -0,0 +1,18 @@
1
+ # Encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'tomodel'
5
+
6
+
7
+ describe 'Model' do
8
+ before(:all) do
9
+ toModel = ToModel.new
10
+ samplefile =File.join(File.dirname(__FILE__), 'sample_data', 'sample.xlsx')
11
+ @model = toModel.to_model(samplefile)
12
+ end
13
+ it "will find something with a name" do
14
+ organization = @model.organizations[0]
15
+ organization.name.length.should > 0
16
+ end
17
+ end
18
+
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'thor'
4
+ gem 'fruit_to_lime'
5
+ gem 'tiny_tds'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,3 @@
1
+ require "./lib/tomodel"
2
+
3
+ Cli.start(ARGV)
@@ -0,0 +1,53 @@
1
+ require 'fruit_to_lime'
2
+ require 'roo'
3
+ require 'date'
4
+
5
+ class ToModel
6
+ def to_organization(row)
7
+ organization = FruitToLime::Organization.new()
8
+ organization.integration_id = row['id']
9
+ organization.name = row['name']
10
+ return organization
11
+ end
12
+
13
+ def to_model(organization_rows)
14
+ model = FruitToLime::RootModel.new
15
+
16
+ organization_rows.each do |row|
17
+ model.organizations.push(to_organization(row))
18
+ end
19
+
20
+ return model
21
+ end
22
+ end
23
+
24
+ require "thor"
25
+ require "fileutils"
26
+ require 'pathname'
27
+ require 'tiny_tds'
28
+
29
+ class Cli < Thor
30
+ desc "to_go", "Connects to sql server and queries for organizations to Go xml format. HOST, DATABASE, USERNAME and PASSWORD for Sql server connection. FILE is output file where Go xml will go."
31
+ def to_go(host, database, username, password, file = nil)
32
+ puts "Connecting to database #{database} on server #{host} as user #{username}"
33
+ client = TinyTds::Client.new(
34
+ :username => username,
35
+ :password => password,
36
+ :host => host,
37
+ :database => database)
38
+
39
+ organizationSql =
40
+ "SELECT
41
+ c.id,
42
+ c.name,
43
+ FROM
44
+ company c"
45
+
46
+ organization_rows = client.execute(organizationSql)
47
+
48
+ file = 'export.xml' if file == nil
49
+ tomodel = ToModel.new()
50
+ model = tomodel.to_model(organization_rows)
51
+ model.serialize_to_file(file)
52
+ end
53
+ end
@@ -0,0 +1,20 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ #require File.expand_path("../../config/environment", __FILE__)
3
+ require 'rspec/autorun'
4
+
5
+ RSpec.configure do |config|
6
+ # ## Mock Framework
7
+ #
8
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
9
+ #
10
+ # config.mock_with :mocha
11
+ # config.mock_with :flexmock
12
+ # config.mock_with :rr
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = "random"
19
+ end
20
+
@@ -0,0 +1,9 @@
1
+ # Encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'tomodel'
5
+
6
+ describe 'Model' do
7
+
8
+ end
9
+
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.7
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-07 00:00:00.000000000 Z
13
+ date: 2013-11-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: iso_country_codes
@@ -65,12 +65,12 @@ description: ! ' With this small library it should be much easier to generate i
65
65
 
66
66
  '
67
67
  email: oskar.gewalli@lundalogik.se
68
- executables: []
68
+ executables:
69
+ - fruit_to_lime
69
70
  extensions: []
70
71
  extra_rdoc_files: []
71
72
  files:
72
73
  - lib/fruit_to_lime/address_helper.rb
73
- - lib/fruit_to_lime/column.rb
74
74
  - lib/fruit_to_lime/csv_helper.rb
75
75
  - lib/fruit_to_lime/model/address.rb
76
76
  - lib/fruit_to_lime/model/coworker_reference.rb
@@ -78,13 +78,33 @@ files:
78
78
  - lib/fruit_to_lime/model/note.rb
79
79
  - lib/fruit_to_lime/model/organization.rb
80
80
  - lib/fruit_to_lime/model/person.rb
81
+ - lib/fruit_to_lime/model/referencetosource.rb
81
82
  - lib/fruit_to_lime/model/rootmodel.rb
82
- - lib/fruit_to_lime/model/sourceref.rb
83
83
  - lib/fruit_to_lime/model/tag.rb
84
84
  - lib/fruit_to_lime/roo_helper.rb
85
85
  - lib/fruit_to_lime/serialize_helper.rb
86
86
  - lib/fruit_to_lime.rb
87
- - spec/gosourceref_spec.rb
87
+ - bin/fruit_to_lime
88
+ - templates/csv/convert.rb
89
+ - templates/csv/Gemfile
90
+ - templates/csv/lib/tomodel.rb
91
+ - templates/csv/Rakefile.rb
92
+ - templates/csv/spec/sample_data/organizations.csv
93
+ - templates/csv/spec/spec_helper.rb
94
+ - templates/csv/spec/tomodel_spec.rb
95
+ - templates/excel/convert.rb
96
+ - templates/excel/Gemfile
97
+ - templates/excel/lib/tomodel.rb
98
+ - templates/excel/Rakefile.rb
99
+ - templates/excel/spec/sample_data/sample.xlsx
100
+ - templates/excel/spec/spec_helper.rb
101
+ - templates/excel/spec/tomodel_spec.rb
102
+ - templates/sqlserver/convert.rb
103
+ - templates/sqlserver/Gemfile
104
+ - templates/sqlserver/lib/tomodel.rb
105
+ - templates/sqlserver/Rakefile.rb
106
+ - templates/sqlserver/spec/spec_helper.rb
107
+ - templates/sqlserver/spec/tomodel_spec.rb
88
108
  - spec/helpers/address_helper_spec.rb
89
109
  - spec/helpers/csv_helper_spec.rb
90
110
  - spec/helpers/roo_helper_spec.rb
@@ -116,7 +136,6 @@ signing_key:
116
136
  specification_version: 3
117
137
  summary: Library to generate Lime Go xml import format
118
138
  test_files:
119
- - spec/gosourceref_spec.rb
120
139
  - spec/helpers/address_helper_spec.rb
121
140
  - spec/helpers/csv_helper_spec.rb
122
141
  - spec/helpers/roo_helper_spec.rb
@@ -1,37 +0,0 @@
1
- module FruitToLime
2
- def self.map_column(column)
3
- return {
4
- :column=>column.column,
5
- :selected=>column.selected
6
- }
7
- end
8
- class Column
9
- attr_accessor :column, :selected
10
- def initialize(options=nil)
11
- if options!=nil
12
- @column = options[:column]
13
- @selected = options[:selected]
14
- end
15
- end
16
- def []=(val, value)
17
- case val
18
- when 'column'
19
- @column = value
20
- when 'selected'
21
- @selected = value
22
- else
23
- raise "Missing! #{val}"
24
- end
25
- end
26
- def [](val)
27
- case val
28
- when 'column'
29
- return @column
30
- when 'selected'
31
- return @selected
32
- else
33
- raise "Missing! #{val}"
34
- end
35
- end
36
- end
37
- end
@@ -1,75 +0,0 @@
1
- module FruitToLime
2
- class GoSourceRef
3
- attr_accessor :name, :id
4
- def initialize(opt=nil)
5
- if opt!=nil
6
- @name = opt[:name]
7
- @id = opt[:id]
8
- else
9
- @name =""
10
- @id =""
11
- end
12
- end
13
- def value
14
- return to_s
15
- end
16
- def value=(str)
17
- m = str.match(/([a-zA-Z]+)(\d+)/)
18
- if !m
19
- raise "Parse error!"
20
- end
21
- @name = m[1]
22
- @id = m[2]
23
- end
24
- def self.parse(str)
25
- v = GoSourceRef.new
26
- v.value = str
27
- return v
28
- end
29
- def self.can_parse(str)
30
- begin
31
- self.parse(str)
32
- return true
33
- rescue Exception => e
34
- return false
35
- end
36
- end
37
- def to_s
38
- return "#{@name}#{@id}"
39
- end
40
- def ==(other)
41
- return @name == other.name && @id == other.id
42
- end
43
- end
44
-
45
- class SourceRef
46
- include SerializeHelper
47
- attr_accessor :name, :id, :format
48
- def serialize_variables
49
- [:name, :id, :format].map { |prop| {:id=>prop,:type=>:string} }
50
- end
51
- def serialize_name
52
- "ExternalSourceRef"
53
- end
54
- def get_import_rows
55
- (serialize_variables+[{:id=>:value, :type=>:string}]).map do |p|
56
- map_to_row p
57
- end
58
- end
59
- def initialize(opt=nil)
60
- if opt!=nil
61
- serialize_variables.each do |myattr|
62
- val = opt[myattr[:id]]
63
- instance_variable_set("@"+myattr[:id].to_s,val) if val!=nil
64
- end
65
- end
66
- end
67
-
68
- def to_s
69
- return "#{@name}_#{@format}_#{@id}"
70
- end
71
- def ==(other)
72
- return @name == other.name && @id == other.id && @format== other.format
73
- end
74
- end
75
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
- require 'fruit_to_lime'
3
-
4
- class T
5
- def self.Par(str)
6
- return "PXX#{str}"
7
- end
8
- def self.PAR
9
- return "PXX"
10
- end
11
- end
12
-
13
- describe FruitToLime::GoSourceRef do
14
-
15
- it "can parse simple par id" do
16
- FruitToLime::GoSourceRef.parse(T.Par("123")).should eq FruitToLime::GoSourceRef.new({:name=>T.PAR,:id=> "123"})
17
- end
18
-
19
- it "can parse long id" do
20
- FruitToLime::GoSourceRef.parse("PASE123").should eq FruitToLime::GoSourceRef.new({:name=>"PASE",:id=> "123"})
21
- end
22
-
23
- it "will fail for invalid id" do
24
- expect { FruitToLime::GoSourceRef.parse("123") }.to raise_error
25
- end
26
-
27
- it "can render as expected id" do
28
- FruitToLime::GoSourceRef.new({:name=>T.PAR,:id=> "123"}).to_s.should eq T.Par("123")
29
- end
30
-
31
- it "can verify a valid string" do
32
- FruitToLime::GoSourceRef.can_parse(T.Par("123")).should eq true
33
- end
34
-
35
- it "can verify an invalid string" do
36
- FruitToLime::GoSourceRef.can_parse("123").should eq false
37
- end
38
-
39
- end