excel_import 0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +212 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +51 -0
- data/excel_import.gemspec +67 -0
- data/lib/excel_import.rb +5 -0
- data/lib/excel_import/adapters/program.rb +34 -0
- data/lib/excel_import/excel_loader.rb +150 -0
- data/test/helper.rb +34 -0
- data/test/test_excel_import.rb +7 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 33c6776421e67e9ecff04a280a7dffa539f3e1aa0fcff8bfdf4fc5e42126ae51
|
4
|
+
data.tar.gz: ab595dcdd29490fd2634e8f4d8ded6ead1a807ddabe696cd054ae3424cfe3b19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2794fb074e39c75f00a14860671700dc6006e33229029c473bfc44097e6810316b8397f02d1067e9b1432f77cf7c13db1c4c42ca29b0a0c0dd26ece74e4f7c0
|
7
|
+
data.tar.gz: fa6f9f0b27c7b6a13d9c7695118e177e578a6cbb01db8aa4b9a14f977bdf1f20f7aefafe0931d68614b888c0762842fdfb153a33f94cfa4a910a0db5e2d50999
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 2.0.1"
|
12
|
+
gem "juwelier"
|
13
|
+
gem "simplecov", ">= 0"
|
14
|
+
gem 'datashift', github: 'omairrazam/datashift', branch: '3-2-stable'
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/omairrazam/datashift.git
|
3
|
+
revision: 255525508b3737423ae95b1fd621ad174e7521f0
|
4
|
+
branch: 3-2-stable
|
5
|
+
specs:
|
6
|
+
datashift (0.40.1)
|
7
|
+
erubis (~> 2.7.0)
|
8
|
+
paperclip (>= 4)
|
9
|
+
rails (>= 4.2, < 6.0)
|
10
|
+
rubyzip (~> 1.2)
|
11
|
+
spreadsheet (~> 1.1)
|
12
|
+
thor (>= 0.19.1)
|
13
|
+
thread_safe (~> 0.3, >= 0.3)
|
14
|
+
|
15
|
+
GEM
|
16
|
+
remote: https://rubygems.org/
|
17
|
+
specs:
|
18
|
+
actioncable (5.2.3)
|
19
|
+
actionpack (= 5.2.3)
|
20
|
+
nio4r (~> 2.0)
|
21
|
+
websocket-driver (>= 0.6.1)
|
22
|
+
actionmailer (5.2.3)
|
23
|
+
actionpack (= 5.2.3)
|
24
|
+
actionview (= 5.2.3)
|
25
|
+
activejob (= 5.2.3)
|
26
|
+
mail (~> 2.5, >= 2.5.4)
|
27
|
+
rails-dom-testing (~> 2.0)
|
28
|
+
actionpack (5.2.3)
|
29
|
+
actionview (= 5.2.3)
|
30
|
+
activesupport (= 5.2.3)
|
31
|
+
rack (~> 2.0)
|
32
|
+
rack-test (>= 0.6.3)
|
33
|
+
rails-dom-testing (~> 2.0)
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
35
|
+
actionview (5.2.3)
|
36
|
+
activesupport (= 5.2.3)
|
37
|
+
builder (~> 3.1)
|
38
|
+
erubi (~> 1.4)
|
39
|
+
rails-dom-testing (~> 2.0)
|
40
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
41
|
+
activejob (5.2.3)
|
42
|
+
activesupport (= 5.2.3)
|
43
|
+
globalid (>= 0.3.6)
|
44
|
+
activemodel (5.2.3)
|
45
|
+
activesupport (= 5.2.3)
|
46
|
+
activerecord (5.2.3)
|
47
|
+
activemodel (= 5.2.3)
|
48
|
+
activesupport (= 5.2.3)
|
49
|
+
arel (>= 9.0)
|
50
|
+
activestorage (5.2.3)
|
51
|
+
actionpack (= 5.2.3)
|
52
|
+
activerecord (= 5.2.3)
|
53
|
+
marcel (~> 0.3.1)
|
54
|
+
activesupport (5.2.3)
|
55
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
56
|
+
i18n (>= 0.7, < 2)
|
57
|
+
minitest (~> 5.1)
|
58
|
+
tzinfo (~> 1.1)
|
59
|
+
addressable (2.7.0)
|
60
|
+
public_suffix (>= 2.0.2, < 5.0)
|
61
|
+
arel (9.0.0)
|
62
|
+
builder (3.2.3)
|
63
|
+
climate_control (0.2.0)
|
64
|
+
concurrent-ruby (1.1.5)
|
65
|
+
crass (1.0.4)
|
66
|
+
descendants_tracker (0.0.4)
|
67
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
68
|
+
docile (1.3.2)
|
69
|
+
erubi (1.9.0)
|
70
|
+
erubis (2.7.0)
|
71
|
+
faraday (0.17.0)
|
72
|
+
multipart-post (>= 1.2, < 3)
|
73
|
+
git (1.5.0)
|
74
|
+
github_api (0.18.2)
|
75
|
+
addressable (~> 2.4)
|
76
|
+
descendants_tracker (~> 0.0.4)
|
77
|
+
faraday (~> 0.8)
|
78
|
+
hashie (~> 3.5, >= 3.5.2)
|
79
|
+
oauth2 (~> 1.0)
|
80
|
+
globalid (0.4.2)
|
81
|
+
activesupport (>= 4.2.0)
|
82
|
+
hashie (3.6.0)
|
83
|
+
highline (2.0.2)
|
84
|
+
i18n (1.7.0)
|
85
|
+
concurrent-ruby (~> 1.0)
|
86
|
+
json (1.8.6)
|
87
|
+
juwelier (2.4.9)
|
88
|
+
builder
|
89
|
+
bundler
|
90
|
+
git
|
91
|
+
github_api
|
92
|
+
highline
|
93
|
+
kamelcase (~> 0)
|
94
|
+
nokogiri
|
95
|
+
psych
|
96
|
+
rake
|
97
|
+
rdoc
|
98
|
+
semver2
|
99
|
+
jwt (2.2.1)
|
100
|
+
kamelcase (0.0.2)
|
101
|
+
semver2 (~> 3)
|
102
|
+
loofah (2.3.0)
|
103
|
+
crass (~> 1.0.2)
|
104
|
+
nokogiri (>= 1.5.9)
|
105
|
+
mail (2.7.1)
|
106
|
+
mini_mime (>= 0.1.1)
|
107
|
+
marcel (0.3.3)
|
108
|
+
mimemagic (~> 0.3.2)
|
109
|
+
method_source (0.9.2)
|
110
|
+
mime-types (3.3)
|
111
|
+
mime-types-data (~> 3.2015)
|
112
|
+
mime-types-data (3.2019.0904)
|
113
|
+
mimemagic (0.3.3)
|
114
|
+
mini_mime (1.0.2)
|
115
|
+
mini_portile2 (2.4.0)
|
116
|
+
minitest (5.12.2)
|
117
|
+
multi_json (1.13.1)
|
118
|
+
multi_xml (0.6.0)
|
119
|
+
multipart-post (2.1.1)
|
120
|
+
nio4r (2.5.2)
|
121
|
+
nokogiri (1.10.4)
|
122
|
+
mini_portile2 (~> 2.4.0)
|
123
|
+
oauth2 (1.4.2)
|
124
|
+
faraday (>= 0.8, < 2.0)
|
125
|
+
jwt (>= 1.0, < 3.0)
|
126
|
+
multi_json (~> 1.3)
|
127
|
+
multi_xml (~> 0.5)
|
128
|
+
rack (>= 1.2, < 3)
|
129
|
+
paperclip (6.1.0)
|
130
|
+
activemodel (>= 4.2.0)
|
131
|
+
activesupport (>= 4.2.0)
|
132
|
+
mime-types
|
133
|
+
mimemagic (~> 0.3.0)
|
134
|
+
terrapin (~> 0.6.0)
|
135
|
+
psych (3.1.0)
|
136
|
+
public_suffix (4.0.1)
|
137
|
+
rack (2.0.7)
|
138
|
+
rack-test (1.1.0)
|
139
|
+
rack (>= 1.0, < 3)
|
140
|
+
rails (5.2.3)
|
141
|
+
actioncable (= 5.2.3)
|
142
|
+
actionmailer (= 5.2.3)
|
143
|
+
actionpack (= 5.2.3)
|
144
|
+
actionview (= 5.2.3)
|
145
|
+
activejob (= 5.2.3)
|
146
|
+
activemodel (= 5.2.3)
|
147
|
+
activerecord (= 5.2.3)
|
148
|
+
activestorage (= 5.2.3)
|
149
|
+
activesupport (= 5.2.3)
|
150
|
+
bundler (>= 1.3.0)
|
151
|
+
railties (= 5.2.3)
|
152
|
+
sprockets-rails (>= 2.0.0)
|
153
|
+
rails-dom-testing (2.0.3)
|
154
|
+
activesupport (>= 4.2.0)
|
155
|
+
nokogiri (>= 1.6)
|
156
|
+
rails-html-sanitizer (1.3.0)
|
157
|
+
loofah (~> 2.3)
|
158
|
+
railties (5.2.3)
|
159
|
+
actionpack (= 5.2.3)
|
160
|
+
activesupport (= 5.2.3)
|
161
|
+
method_source
|
162
|
+
rake (>= 0.8.7)
|
163
|
+
thor (>= 0.19.0, < 2.0)
|
164
|
+
rake (13.0.0)
|
165
|
+
rdoc (3.12.2)
|
166
|
+
json (~> 1.4)
|
167
|
+
ruby-ole (1.2.12.2)
|
168
|
+
rubyzip (1.3.0)
|
169
|
+
semver2 (3.4.2)
|
170
|
+
shoulda (3.6.0)
|
171
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
172
|
+
shoulda-matchers (~> 3.0)
|
173
|
+
shoulda-context (1.2.2)
|
174
|
+
shoulda-matchers (3.1.3)
|
175
|
+
activesupport (>= 4.0.0)
|
176
|
+
simplecov (0.17.1)
|
177
|
+
docile (~> 1.1)
|
178
|
+
json (>= 1.8, < 3)
|
179
|
+
simplecov-html (~> 0.10.0)
|
180
|
+
simplecov-html (0.10.2)
|
181
|
+
spreadsheet (1.2.4)
|
182
|
+
ruby-ole (>= 1.0)
|
183
|
+
sprockets (3.7.2)
|
184
|
+
concurrent-ruby (~> 1.0)
|
185
|
+
rack (> 1, < 3)
|
186
|
+
sprockets-rails (3.2.1)
|
187
|
+
actionpack (>= 4.0)
|
188
|
+
activesupport (>= 4.0)
|
189
|
+
sprockets (>= 3.0.0)
|
190
|
+
terrapin (0.6.0)
|
191
|
+
climate_control (>= 0.0.3, < 1.0)
|
192
|
+
thor (0.20.3)
|
193
|
+
thread_safe (0.3.6)
|
194
|
+
tzinfo (1.2.5)
|
195
|
+
thread_safe (~> 0.1)
|
196
|
+
websocket-driver (0.7.1)
|
197
|
+
websocket-extensions (>= 0.1.0)
|
198
|
+
websocket-extensions (0.1.4)
|
199
|
+
|
200
|
+
PLATFORMS
|
201
|
+
ruby
|
202
|
+
|
203
|
+
DEPENDENCIES
|
204
|
+
bundler (~> 2.0.1)
|
205
|
+
datashift!
|
206
|
+
juwelier
|
207
|
+
rdoc (~> 3.12)
|
208
|
+
shoulda
|
209
|
+
simplecov
|
210
|
+
|
211
|
+
BUNDLED WITH
|
212
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2019 omairazam
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= excel_import
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to excel_import
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2019 omairazam. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'juwelier'
|
15
|
+
Juwelier::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "excel_import"
|
18
|
+
gem.homepage = "http://github.com/omairazam/excel_import"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{one-line summary of your gem}
|
21
|
+
gem.description = %Q{longer description of your gem}
|
22
|
+
gem.email = "omsolutionpk@gmail.com"
|
23
|
+
gem.authors = ["omairazam"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Juwelier::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Code coverage detail"
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = "true"
|
38
|
+
Rake::Task['test'].execute
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "excel_import #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by juwelier
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: excel_import 0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "excel_import".freeze
|
9
|
+
s.version = "0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["omairazam".freeze]
|
14
|
+
s.date = "2019-10-07"
|
15
|
+
s.description = "longer description of your gem".freeze
|
16
|
+
s.email = "omsolutionpk@gmail.com".freeze
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"excel_import.gemspec",
|
29
|
+
"lib/excel_import.rb",
|
30
|
+
"lib/excel_import/adapters/program.rb",
|
31
|
+
"lib/excel_import/excel_loader.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_excel_import.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/omairazam/excel_import".freeze
|
36
|
+
s.licenses = ["MIT".freeze]
|
37
|
+
s.rubygems_version = "3.0.3".freeze
|
38
|
+
s.summary = "one-line summary of your gem".freeze
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 4
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_development_dependency(%q<shoulda>.freeze, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
46
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 2.0.1"])
|
47
|
+
s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<datashift>.freeze, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<shoulda>.freeze, [">= 0"])
|
52
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
53
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 2.0.1"])
|
54
|
+
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
55
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
56
|
+
s.add_dependency(%q<datashift>.freeze, [">= 0"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<shoulda>.freeze, [">= 0"])
|
60
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
61
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 2.0.1"])
|
62
|
+
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
63
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
64
|
+
s.add_dependency(%q<datashift>.freeze, [">= 0"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
data/lib/excel_import.rb
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
module ExcelImport
|
2
|
+
Dir[File.dirname(__FILE__) + "/excel_import/*.rb"].each {|file| require file }
|
3
|
+
Dir[File.dirname(__FILE__) + "/excel_import/adapters/*.rb"].each {|file| require file }
|
4
|
+
Dir[File.dirname(__FILE__) + "/excel_import/extractors/*.rb"].each {|file| require file }
|
5
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ExcelImport
|
2
|
+
module Adapters
|
3
|
+
class Program < DataShift::Excel
|
4
|
+
# HEADERS = [:loan_purpose, :loan_size, :loan_type, :team, :interest_rate, :lock_period, :fannie_mae, :base_rate, :adjustment_rate]
|
5
|
+
HEADERS = [:base_rate, :adjustment_rate, :loan_size, :loan_type, :term, :fannie_mae]
|
6
|
+
|
7
|
+
attr_accessor :headers, :start_index, :reached_end
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
@headers = HEADERS
|
12
|
+
end
|
13
|
+
|
14
|
+
def sheet_final
|
15
|
+
@current_sheet = self.worksheets.first
|
16
|
+
ret = []
|
17
|
+
ret << get_single_row
|
18
|
+
ret
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_single_row
|
22
|
+
extractor = ProgramExtractor.new @current_sheet
|
23
|
+
base_rate = extractor.base_rate.to_json
|
24
|
+
adjustment_rate = extractor.adjustment_rate.to_json
|
25
|
+
loan_size = extractor.loan_size
|
26
|
+
loan_type = extractor.loan_type
|
27
|
+
term = extractor.term
|
28
|
+
fannie_mae = true
|
29
|
+
|
30
|
+
return [base_rate, adjustment_rate, loan_size, loan_type, term, fannie_mae]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module ExcelImport
|
2
|
+
# Copyright:: (c) Autotelik Media Ltd 2015
|
3
|
+
# Author :: Tom Statter
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Specific loader to support Excel files.
|
7
|
+
# Note this only requires JRuby, Excel not required, nor Win OLE.
|
8
|
+
#
|
9
|
+
# Maps column headings to operations on the model.
|
10
|
+
# Iterates over all the rows using mapped operations to assign row data to a database object,
|
11
|
+
# i.e pulls data from each column and sends to object.
|
12
|
+
#
|
13
|
+
gem_dir = Gem::Specification.find_by_name("datashift").gem_dir
|
14
|
+
require "#{gem_dir}/lib/datashift/loaders/file_loader"
|
15
|
+
|
16
|
+
|
17
|
+
class ExcelLoader < DataShift::LoaderBase
|
18
|
+
|
19
|
+
include DataShift::ExcelBase
|
20
|
+
include DataShift::FileLoader
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def run(file_name, load_class, excel_instance)
|
27
|
+
@file_name = file_name
|
28
|
+
@excel = excel_instance
|
29
|
+
setup_load_class(load_class)
|
30
|
+
|
31
|
+
logger.info("Loading objects of type #{load_object_class}")
|
32
|
+
|
33
|
+
perform_load
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def perform_load(options = {})
|
38
|
+
|
39
|
+
allow_empty_rows = DataShift::Loaders::Configuration.call.allow_empty_rows
|
40
|
+
|
41
|
+
logger.info "Starting bulk load from Excel : #{file_name}"
|
42
|
+
|
43
|
+
start(file_name, options)
|
44
|
+
|
45
|
+
# maps list of headers into suitable calls on the Active Record class
|
46
|
+
bind_headers(headers)
|
47
|
+
|
48
|
+
is_dummy_run = DataShift::Configuration.call.dummy_run
|
49
|
+
|
50
|
+
begin
|
51
|
+
puts 'Dummy Run - Changes will be rolled back' if is_dummy_run
|
52
|
+
|
53
|
+
load_object_class.transaction do
|
54
|
+
@excel.sheet_final.each_with_index do |row, current_row_idx|
|
55
|
+
# next if current_row_idx == headers.idx
|
56
|
+
# Excel num_rows seems to return all 'visible' rows, which appears to be greater than the actual data rows
|
57
|
+
# (TODO - write spec to process .xls with a huge number of rows)
|
58
|
+
#
|
59
|
+
# manually have to detect when actual data ends, this isn't very smart but
|
60
|
+
# got no better idea than ending once we hit the first completely empty row
|
61
|
+
break if !allow_empty_rows && (row.nil? || row.empty?)
|
62
|
+
|
63
|
+
logger.info "Processing Row #{current_row_idx}"
|
64
|
+
|
65
|
+
contains_data = false
|
66
|
+
|
67
|
+
doc_context.progress_monitor.start_monitoring
|
68
|
+
# Iterate over the bindings,
|
69
|
+
# For each column bound to a model operator, create a context from data in associated Excel column
|
70
|
+
@binder.bindings.each do |method_binding|
|
71
|
+
|
72
|
+
unless method_binding.valid?
|
73
|
+
logger.warn("No binding was found for column (#{current_row_idx})")
|
74
|
+
next
|
75
|
+
end
|
76
|
+
|
77
|
+
# If binding to a column, get the value from the cell (bindings can be to internal methods)
|
78
|
+
value = method_binding.index ? row[method_binding.index] : nil
|
79
|
+
context = doc_context.create_node_context(method_binding, current_row_idx, value)
|
80
|
+
|
81
|
+
contains_data ||= context.contains_data?
|
82
|
+
|
83
|
+
logger.info "Processing Column #{method_binding.index} (#{method_binding.pp})"
|
84
|
+
begin
|
85
|
+
context.process
|
86
|
+
rescue
|
87
|
+
if doc_context.all_or_nothing?
|
88
|
+
logger.error('All or nothing set and Current Column failed so complete Row aborted')
|
89
|
+
break
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
# Excel data rows not accurate, seems to have to manually detect when actual Excel data rows end
|
96
|
+
break if !allow_empty_rows && contains_data == false
|
97
|
+
doc_context.save_and_monitor_progress
|
98
|
+
|
99
|
+
# unless next operation is update, reset the loader object
|
100
|
+
doc_context.reset unless doc_context.node_context.next_update?
|
101
|
+
end # all rows processed
|
102
|
+
|
103
|
+
if is_dummy_run
|
104
|
+
puts 'Excel loading stage done - Dummy run so Rolling Back.'
|
105
|
+
raise ActiveRecord::Rollback # Don't actually create/upload to DB if we are doing dummy run
|
106
|
+
end
|
107
|
+
end # TRANSACTION N.B ActiveRecord::Rollback does not propagate outside of the containing transaction block
|
108
|
+
|
109
|
+
rescue => e
|
110
|
+
puts "ERROR: Excel loading failed : #{e.inspect}"
|
111
|
+
raise e
|
112
|
+
ensure
|
113
|
+
report
|
114
|
+
end
|
115
|
+
|
116
|
+
puts 'Excel loading stage Complete.'
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def start(file_name, options = {})
|
122
|
+
open_excel(file_name, options)
|
123
|
+
set_headers(parse_headers(@excel.headers))
|
124
|
+
if headers.empty?
|
125
|
+
raise MissingHeadersError, "No headers found - Check Sheet #{sheet} is complete and Row #{headers.idx} contains headers"
|
126
|
+
end
|
127
|
+
|
128
|
+
excel
|
129
|
+
end
|
130
|
+
|
131
|
+
def parse_headers(header_row, header_row_idx = 0)
|
132
|
+
|
133
|
+
headers = DataShift::Headers.new(:excel, header_row_idx)
|
134
|
+
|
135
|
+
# TODO: - make more robust - currently end on first empty column
|
136
|
+
# There is no actual max columns in Excel .. you will run out of memory though at some point
|
137
|
+
(0..::DataShift::ExcelBase.max_columns).each do |column|
|
138
|
+
cell = header_row[column]
|
139
|
+
break unless cell
|
140
|
+
header = cell.to_s.strip
|
141
|
+
break if header.empty?
|
142
|
+
headers << header
|
143
|
+
end
|
144
|
+
|
145
|
+
headers
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
require 'rubygems'
|
18
|
+
require 'bundler'
|
19
|
+
begin
|
20
|
+
Bundler.setup(:default, :development)
|
21
|
+
rescue Bundler::BundlerError => e
|
22
|
+
$stderr.puts e.message
|
23
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
+
exit e.status_code
|
25
|
+
end
|
26
|
+
require 'test/unit'
|
27
|
+
require 'shoulda'
|
28
|
+
|
29
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
30
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
31
|
+
require 'excel_import'
|
32
|
+
|
33
|
+
class Test::Unit::TestCase
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: excel_import
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- omairazam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shoulda
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: juwelier
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: datashift
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: longer description of your gem
|
98
|
+
email: omsolutionpk@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.rdoc
|
104
|
+
files:
|
105
|
+
- ".document"
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.rdoc
|
110
|
+
- Rakefile
|
111
|
+
- excel_import.gemspec
|
112
|
+
- lib/excel_import.rb
|
113
|
+
- lib/excel_import/adapters/program.rb
|
114
|
+
- lib/excel_import/excel_loader.rb
|
115
|
+
- test/helper.rb
|
116
|
+
- test/test_excel_import.rb
|
117
|
+
homepage: http://github.com/omairazam/excel_import
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.0.3
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: one-line summary of your gem
|
140
|
+
test_files: []
|