datashift 0.1.0 → 0.2.1
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/.document +5 -5
- data/LICENSE.txt +26 -26
- data/README.markdown +305 -303
- data/README.rdoc +19 -19
- data/Rakefile +93 -93
- data/VERSION +1 -1
- data/datashift-0.1.0.gem +0 -0
- data/datashift.gemspec +152 -136
- data/lib/applications/jruby/jexcel_file.rb +408 -408
- data/lib/applications/jruby/word.rb +79 -79
- data/lib/datashift.rb +152 -152
- data/lib/datashift/exceptions.rb +11 -11
- data/lib/datashift/file_definitions.rb +353 -353
- data/lib/datashift/mapping_file_definitions.rb +87 -87
- data/lib/datashift/method_detail.rb +275 -275
- data/lib/datashift/method_dictionary.rb +209 -209
- data/lib/datashift/method_mapper.rb +90 -90
- data/lib/generators/csv_generator.rb +36 -36
- data/lib/generators/excel_generator.rb +122 -122
- data/lib/generators/generator_base.rb +13 -13
- data/lib/helpers/core_ext/to_b.rb +24 -24
- data/lib/helpers/spree_helper.rb +153 -155
- data/lib/java/poi-3.7/LICENSE +507 -507
- data/lib/java/poi-3.7/NOTICE +21 -21
- data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -115
- data/lib/loaders/csv_loader.rb +98 -98
- data/lib/loaders/excel_loader.rb +155 -155
- data/lib/loaders/loader_base.rb +420 -420
- data/lib/loaders/spreadsheet_loader.rb +136 -136
- data/lib/loaders/spree/image_loader.rb +63 -64
- data/lib/loaders/spree/product_loader.rb +248 -250
- data/public/spree/products/large/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/large/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/large/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/mini/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/mini/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/mini/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/original/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/original/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/original/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/product/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/product/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/product/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/small/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/small/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/small/DEMO_003_ror_mug.jpeg +0 -0
- data/spec/csv_loader_spec.rb +30 -30
- data/spec/datashift_spec.rb +26 -26
- data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -85
- data/spec/excel_exporter_spec.rb +78 -78
- data/spec/excel_generator_spec.rb +78 -78
- data/spec/excel_loader_spec.rb +223 -223
- data/spec/file_definitions.rb +141 -141
- data/spec/fixtures/ProjectsDefaults.yml +29 -29
- data/spec/fixtures/config/database.yml +27 -24
- data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
- data/spec/fixtures/interact_models_db.sqlite +0 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -4
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -4
- data/spec/fixtures/spree/SpreeProducts.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsWithImages.csv +4 -0
- data/spec/fixtures/spree/SpreeZoneExample.csv +5 -5
- data/spec/fixtures/test_model_defs.rb +57 -57
- data/spec/loader_spec.rb +120 -120
- data/spec/method_dictionary_spec.rb +242 -242
- data/spec/method_mapper_spec.rb +41 -41
- data/spec/spec_helper.rb +116 -116
- data/spec/spree_generator_spec.rb +64 -64
- data/spec/spree_loader_spec.rb +324 -327
- data/spec/spree_method_mapping_spec.rb +214 -214
- data/tasks/config/seed_fu_product_template.erb +15 -15
- data/tasks/config/tidy_config.txt +12 -12
- data/tasks/db_tasks.rake +65 -65
- data/tasks/excel_generator.rake +78 -78
- data/tasks/file_tasks.rake +36 -36
- data/tasks/import/csv.rake +49 -49
- data/tasks/import/excel.rake +71 -71
- data/tasks/spree/image_load.rake +108 -108
- data/tasks/spree/product_loader.rake +43 -43
- data/tasks/word_to_seedfu.rake +166 -166
- data/test/helper.rb +18 -18
- data/test/test_interact.rb +7 -7
- metadata +22 -3
- data/spec/fixtures/interact_spree_db.sqlite +0 -0
@@ -1,79 +1,79 @@
|
|
1
|
-
# Author:: Tom Statter
|
2
|
-
# License:: MIT ?
|
3
|
-
#
|
4
|
-
# NOTES ON INVESTIGATING OLE METHODS in irb
|
5
|
-
#
|
6
|
-
# visible = @word_app.ole_method_help( 'Visible' ) # Get a Method Object
|
7
|
-
|
8
|
-
# log( visible.return_type_detail.to_s ) # => ["BOOL"]
|
9
|
-
# log( visible.invoke_kind.to_s ) # => "PROPERTYGET"
|
10
|
-
# log( visible.params.to_s ) # => []
|
11
|
-
|
12
|
-
# @fc.ole_method_help( 'Report' ).params[1].ole_type_detail
|
13
|
-
#
|
14
|
-
# prefs = @word_app.Preferences.Strings.ole_method_help( 'Set' ).params
|
15
|
-
# => [index, newVal]
|
16
|
-
#
|
17
|
-
# WORD_OLE_CONST.constants
|
18
|
-
#
|
19
|
-
# WORD_OLE_CONST.constants.sort.grep /CR/
|
20
|
-
# => ["ClHideCRLF", "LesCR", "LesCRLF"]
|
21
|
-
#
|
22
|
-
# WORD_OLE_CONST.const_get( 'LesCR' ) or WORD_OLE_CONST::LesCR
|
23
|
-
# => 1
|
24
|
-
|
25
|
-
if(Guards::windows?)
|
26
|
-
|
27
|
-
require 'win32ole'
|
28
|
-
|
29
|
-
# Module for constants to be loaded int
|
30
|
-
|
31
|
-
module WORD_OLE_CONST
|
32
|
-
end
|
33
|
-
|
34
|
-
class Word
|
35
|
-
|
36
|
-
attr_reader :wd, :doc
|
37
|
-
|
38
|
-
def initialize( visible )
|
39
|
-
@wd = WIN32OLE.new('Word.Application')
|
40
|
-
|
41
|
-
WIN32OLE.const_load(@wd, WORD_OLE_CONST) if WORD_OLE_CONST.constants.empty?
|
42
|
-
|
43
|
-
@wd.Visible = visible
|
44
|
-
end
|
45
|
-
|
46
|
-
def open(file)
|
47
|
-
@doc = @wd.Documents.Open(file)
|
48
|
-
@doc
|
49
|
-
end
|
50
|
-
|
51
|
-
def save()
|
52
|
-
@doc.Save()
|
53
|
-
@doc
|
54
|
-
end
|
55
|
-
|
56
|
-
# Format : From WORD_OLE_CONST e.g WORD_OLE_CONST::WdFormatHTML
|
57
|
-
#
|
58
|
-
def save_as(name, format)
|
59
|
-
@doc.SaveAs(name, format)
|
60
|
-
return @doc
|
61
|
-
end
|
62
|
-
|
63
|
-
# WdFormatFilteredHTML
|
64
|
-
# WdFormatHTML
|
65
|
-
def save_as_html(name)
|
66
|
-
@doc.SaveAs(name, WORD_OLE_CONST::WdFormatHTML)
|
67
|
-
return @doc
|
68
|
-
end
|
69
|
-
|
70
|
-
def quit
|
71
|
-
@wd.quit()
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
else
|
76
|
-
|
77
|
-
class Word
|
78
|
-
end
|
79
|
-
end
|
1
|
+
# Author:: Tom Statter
|
2
|
+
# License:: MIT ?
|
3
|
+
#
|
4
|
+
# NOTES ON INVESTIGATING OLE METHODS in irb
|
5
|
+
#
|
6
|
+
# visible = @word_app.ole_method_help( 'Visible' ) # Get a Method Object
|
7
|
+
|
8
|
+
# log( visible.return_type_detail.to_s ) # => ["BOOL"]
|
9
|
+
# log( visible.invoke_kind.to_s ) # => "PROPERTYGET"
|
10
|
+
# log( visible.params.to_s ) # => []
|
11
|
+
|
12
|
+
# @fc.ole_method_help( 'Report' ).params[1].ole_type_detail
|
13
|
+
#
|
14
|
+
# prefs = @word_app.Preferences.Strings.ole_method_help( 'Set' ).params
|
15
|
+
# => [index, newVal]
|
16
|
+
#
|
17
|
+
# WORD_OLE_CONST.constants
|
18
|
+
#
|
19
|
+
# WORD_OLE_CONST.constants.sort.grep /CR/
|
20
|
+
# => ["ClHideCRLF", "LesCR", "LesCRLF"]
|
21
|
+
#
|
22
|
+
# WORD_OLE_CONST.const_get( 'LesCR' ) or WORD_OLE_CONST::LesCR
|
23
|
+
# => 1
|
24
|
+
|
25
|
+
if(Guards::windows?)
|
26
|
+
|
27
|
+
require 'win32ole'
|
28
|
+
|
29
|
+
# Module for constants to be loaded int
|
30
|
+
|
31
|
+
module WORD_OLE_CONST
|
32
|
+
end
|
33
|
+
|
34
|
+
class Word
|
35
|
+
|
36
|
+
attr_reader :wd, :doc
|
37
|
+
|
38
|
+
def initialize( visible )
|
39
|
+
@wd = WIN32OLE.new('Word.Application')
|
40
|
+
|
41
|
+
WIN32OLE.const_load(@wd, WORD_OLE_CONST) if WORD_OLE_CONST.constants.empty?
|
42
|
+
|
43
|
+
@wd.Visible = visible
|
44
|
+
end
|
45
|
+
|
46
|
+
def open(file)
|
47
|
+
@doc = @wd.Documents.Open(file)
|
48
|
+
@doc
|
49
|
+
end
|
50
|
+
|
51
|
+
def save()
|
52
|
+
@doc.Save()
|
53
|
+
@doc
|
54
|
+
end
|
55
|
+
|
56
|
+
# Format : From WORD_OLE_CONST e.g WORD_OLE_CONST::WdFormatHTML
|
57
|
+
#
|
58
|
+
def save_as(name, format)
|
59
|
+
@doc.SaveAs(name, format)
|
60
|
+
return @doc
|
61
|
+
end
|
62
|
+
|
63
|
+
# WdFormatFilteredHTML
|
64
|
+
# WdFormatHTML
|
65
|
+
def save_as_html(name)
|
66
|
+
@doc.SaveAs(name, WORD_OLE_CONST::WdFormatHTML)
|
67
|
+
return @doc
|
68
|
+
end
|
69
|
+
|
70
|
+
def quit
|
71
|
+
@wd.quit()
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
else
|
76
|
+
|
77
|
+
class Word
|
78
|
+
end
|
79
|
+
end
|
data/lib/datashift.rb
CHANGED
@@ -1,153 +1,153 @@
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
-
# Author :: Tom Statter
|
3
|
-
# Date :: Aug 2010
|
4
|
-
# License:: TBD. Free, Open Source. MIT ?
|
5
|
-
#
|
6
|
-
# Details:: Active Record Loader
|
7
|
-
#
|
8
|
-
require 'rbconfig'
|
9
|
-
|
10
|
-
module DataShift
|
11
|
-
|
12
|
-
module Guards
|
13
|
-
|
14
|
-
def self.jruby?
|
15
|
-
return RUBY_PLATFORM == "java"
|
16
|
-
end
|
17
|
-
def self.mac?
|
18
|
-
RbConfig::CONFIG['target_os'] =~ /darwin/i
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.linux?
|
22
|
-
RbConfig::CONFIG['target_os'] =~ /linux/i
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.windows?
|
26
|
-
RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
if(Guards::jruby?)
|
32
|
-
require 'java'
|
33
|
-
|
34
|
-
class Object
|
35
|
-
def add_to_classpath(path)
|
36
|
-
$CLASSPATH << File.join( DataShift.root_path, 'lib', path.gsub("\\", "/") )
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.gem_version
|
42
|
-
unless(@gem_version)
|
43
|
-
if(File.exists?('VERSION'))
|
44
|
-
File.read( File.join('VERSION') ).match(/.*(\d+.\d+.\d+)/)
|
45
|
-
@gem_version = $1
|
46
|
-
else
|
47
|
-
@gem_version = '1.0.0'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
@gem_version
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.gem_name
|
54
|
-
"datashift"
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.root_path
|
58
|
-
File.expand_path("#{File.dirname(__FILE__)}/..")
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.library_path
|
62
|
-
File.expand_path("#{File.dirname(__FILE__)}/../lib")
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.require_libraries
|
66
|
-
|
67
|
-
loader_libs = %w{ lib }
|
68
|
-
|
69
|
-
# Base search paths - these will be searched recursively
|
70
|
-
loader_paths = []
|
71
|
-
|
72
|
-
loader_libs.each {|l| loader_paths << File.join(root_path(), l) }
|
73
|
-
|
74
|
-
# Define require search paths, any dir in here will be added to LOAD_PATH
|
75
|
-
|
76
|
-
loader_paths.each do |base|
|
77
|
-
$:.unshift base if File.directory?(base)
|
78
|
-
Dir[File.join(base, '**', '**')].each do |p|
|
79
|
-
if File.directory? p
|
80
|
-
$:.unshift p
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
require_libs = %w{ datashift loaders helpers }
|
86
|
-
|
87
|
-
require_libs.each do |base|
|
88
|
-
Dir[File.join(library_path, base, '*.rb')].each do |rb|
|
89
|
-
unless File.directory? rb
|
90
|
-
require rb
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.load_tasks
|
98
|
-
# Long parameter lists so ensure rake -T produces nice wide output
|
99
|
-
ENV['RAKE_COLUMNS'] = '180'
|
100
|
-
base = File.join(root_path, 'tasks', '**')
|
101
|
-
Dir["#{base}/*.rake"].sort.each { |ext| load ext }
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
module Logging
|
106
|
-
|
107
|
-
class MultiIO
|
108
|
-
|
109
|
-
def initialize(*targets)
|
110
|
-
@targets = []
|
111
|
-
targets.each {|t| @targets << Logger.new(t) }
|
112
|
-
end
|
113
|
-
|
114
|
-
def add(target)
|
115
|
-
@targets << Logger.new(target)
|
116
|
-
end
|
117
|
-
|
118
|
-
|
119
|
-
def method_missing(method, *args, &block)
|
120
|
-
@targets.each {|t| t.send(method, *args, &block) }
|
121
|
-
end
|
122
|
-
|
123
|
-
def verbose
|
124
|
-
add(STDOUT)
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
require 'logger'
|
130
|
-
|
131
|
-
def logdir
|
132
|
-
@logdir ||= 'log'
|
133
|
-
@logdir
|
134
|
-
end
|
135
|
-
|
136
|
-
def logger
|
137
|
-
@logger ||= open
|
138
|
-
@logger
|
139
|
-
end
|
140
|
-
|
141
|
-
private
|
142
|
-
|
143
|
-
def open( log = 'datashift.log')
|
144
|
-
FileUtils::mkdir(logdir) unless File.directory?(logdir)
|
145
|
-
log_file = File.open( File.join(logdir(), 'datashift.log'), "a")
|
146
|
-
@logger = MultiIO.new(log_file)
|
147
|
-
@logger
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2010
|
4
|
+
# License:: TBD. Free, Open Source. MIT ?
|
5
|
+
#
|
6
|
+
# Details:: Active Record Loader
|
7
|
+
#
|
8
|
+
require 'rbconfig'
|
9
|
+
|
10
|
+
module DataShift
|
11
|
+
|
12
|
+
module Guards
|
13
|
+
|
14
|
+
def self.jruby?
|
15
|
+
return RUBY_PLATFORM == "java"
|
16
|
+
end
|
17
|
+
def self.mac?
|
18
|
+
RbConfig::CONFIG['target_os'] =~ /darwin/i
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.linux?
|
22
|
+
RbConfig::CONFIG['target_os'] =~ /linux/i
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.windows?
|
26
|
+
RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
if(Guards::jruby?)
|
32
|
+
require 'java'
|
33
|
+
|
34
|
+
class Object
|
35
|
+
def add_to_classpath(path)
|
36
|
+
$CLASSPATH << File.join( DataShift.root_path, 'lib', path.gsub("\\", "/") )
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.gem_version
|
42
|
+
unless(@gem_version)
|
43
|
+
if(File.exists?('VERSION'))
|
44
|
+
File.read( File.join('VERSION') ).match(/.*(\d+.\d+.\d+)/)
|
45
|
+
@gem_version = $1
|
46
|
+
else
|
47
|
+
@gem_version = '1.0.0'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
@gem_version
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.gem_name
|
54
|
+
"datashift"
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.root_path
|
58
|
+
File.expand_path("#{File.dirname(__FILE__)}/..")
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.library_path
|
62
|
+
File.expand_path("#{File.dirname(__FILE__)}/../lib")
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.require_libraries
|
66
|
+
|
67
|
+
loader_libs = %w{ lib }
|
68
|
+
|
69
|
+
# Base search paths - these will be searched recursively
|
70
|
+
loader_paths = []
|
71
|
+
|
72
|
+
loader_libs.each {|l| loader_paths << File.join(root_path(), l) }
|
73
|
+
|
74
|
+
# Define require search paths, any dir in here will be added to LOAD_PATH
|
75
|
+
|
76
|
+
loader_paths.each do |base|
|
77
|
+
$:.unshift base if File.directory?(base)
|
78
|
+
Dir[File.join(base, '**', '**')].each do |p|
|
79
|
+
if File.directory? p
|
80
|
+
$:.unshift p
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
require_libs = %w{ datashift loaders helpers }
|
86
|
+
|
87
|
+
require_libs.each do |base|
|
88
|
+
Dir[File.join(library_path, base, '*.rb')].each do |rb|
|
89
|
+
unless File.directory? rb
|
90
|
+
require rb
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.load_tasks
|
98
|
+
# Long parameter lists so ensure rake -T produces nice wide output
|
99
|
+
ENV['RAKE_COLUMNS'] = '180'
|
100
|
+
base = File.join(root_path, 'tasks', '**')
|
101
|
+
Dir["#{base}/*.rake"].sort.each { |ext| load ext }
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
module Logging
|
106
|
+
|
107
|
+
class MultiIO
|
108
|
+
|
109
|
+
def initialize(*targets)
|
110
|
+
@targets = []
|
111
|
+
targets.each {|t| @targets << Logger.new(t) }
|
112
|
+
end
|
113
|
+
|
114
|
+
def add(target)
|
115
|
+
@targets << Logger.new(target)
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def method_missing(method, *args, &block)
|
120
|
+
@targets.each {|t| t.send(method, *args, &block) }
|
121
|
+
end
|
122
|
+
|
123
|
+
def verbose
|
124
|
+
add(STDOUT)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
require 'logger'
|
130
|
+
|
131
|
+
def logdir
|
132
|
+
@logdir ||= 'log'
|
133
|
+
@logdir
|
134
|
+
end
|
135
|
+
|
136
|
+
def logger
|
137
|
+
@logger ||= open
|
138
|
+
@logger
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def open( log = 'datashift.log')
|
144
|
+
FileUtils::mkdir(logdir) unless File.directory?(logdir)
|
145
|
+
log_file = File.open( File.join(logdir(), 'datashift.log'), "a")
|
146
|
+
@logger = MultiIO.new(log_file)
|
147
|
+
@logger
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
153
|
DataShift::require_libraries
|