excel_walker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+ module ExcelWalker::Reader
3
+ describe Reader do
4
+ let(:sheet1) { double(name: 'sheet1', rows: [Hash[(1..10).to_a.zip(%w[a b c d e f g h i k])]]*100) }
5
+ let(:sheet2) { double(name: 'sheet2', rows: [Hash[(1..10).to_a.zip(%w[q r s t u v w x y z])]]*100) }
6
+ let(:sheets) { [sheet1, sheet2] }
7
+ let(:book) { double(sheets: sheets, close: true) }
8
+ before :each do
9
+ Creek::Book.stub(new: book)
10
+ end
11
+ let(:hook1) { double }
12
+ let(:hook2) { double }
13
+ subject(:exl) { Reader.new(:random) }
14
+
15
+ context 'one worksheet' do
16
+ before do
17
+ exl.on_row(4).columns(3).run { |data, row_num| hook1.call(data, row_num) }
18
+ exl.on_row([5, 6]).columns([3, 4]).run { |data, row_num| hook1.call(data, row_num) }
19
+ exl.on_row(5..100).columns(4..20).run { |data, row_num| hook2.call(data, row_num) }
20
+ end
21
+ it 'calls the hooks correctly' do
22
+ hook1.should_receive(:call).with('c', 4)
23
+ hook1.should_receive(:call).with(['c', 'd'], 5)
24
+ hook1.should_receive(:call).with(['c', 'd'], 6)
25
+ hook2.should_receive(:call).exactly(96).times
26
+ expect(exl.start).to eq ['sheet1']
27
+ end
28
+ end
29
+
30
+ context 'one worksheet - block syntax for row matchers and columns plucker' do
31
+ before do
32
+ exl.on_row { |row_num| row_num == 5 }.columns { |row| row[9] }.run { |data, row_num| hook1.call(data, row_num) }
33
+ end
34
+ it 'calls the hooks correctly' do
35
+ hook1.should_receive(:call).with('k', 5)
36
+ expect(exl.start).to eq ['sheet1']
37
+ end
38
+ end
39
+
40
+ context 'two worksheets' do
41
+ before do
42
+ exl.for_sheet(1).on_row([5, 6]).columns([3, 4]).run { |data, row_num| hook1.call(data, row_num) }
43
+ exl.for_sheet(2).on_row([6, 7]).columns([6, 7]).run { |data, row_num| hook2.call(data, row_num) }
44
+ end
45
+ it 'calls the hooks correctly' do
46
+ hook1.should_receive(:call).with(['c', 'd'], 5)
47
+ hook1.should_receive(:call).with(['c', 'd'], 6)
48
+ hook2.should_receive(:call).with(['v', 'w'], 6)
49
+ hook2.should_receive(:call).with(['v', 'w'], 7)
50
+ expect(exl.start).to eq ['sheet1', 'sheet2']
51
+ end
52
+ end
53
+
54
+ context 'one worksheet with row limit' do
55
+ before do
56
+ exl.for_sheet(1).max_rows(20)
57
+ exl.on_row(5..100).columns(4..20).run { |data, row_num| hook1.call(data, row_num) }
58
+ end
59
+ it 'calls the hooks correctly' do
60
+ hook1.should_receive(:call).exactly(16).times
61
+ expect(exl.start).to eq ['sheet1']
62
+ end
63
+ end
64
+
65
+ context 'one worksheet - clearing the hooks' do
66
+ before do
67
+ exl.on_row(5..100).columns(4..20).run { |data, row_num| hook1.call(data, row_num) }
68
+ exl.hooks.clear
69
+ end
70
+ it 'should not call any hooks' do
71
+ hook1.should_not_receive(:call)
72
+ expect(exl.start).to eq ['sheet1']
73
+ end
74
+ end
75
+
76
+ context 'one worksheet with exit clause in one of the blocks' do
77
+ before do
78
+ exl.on_row(5..100).columns(4..20).run { |data, row_num| hook1.call(data, row_num) }
79
+ exl.on_row(75).columns(4..20).run { exl.exit }
80
+ end
81
+ it 'calls the hooks correctly' do
82
+ hook1.should_receive(:call).exactly(71).times
83
+ expect(exl.start).to eq []
84
+ end
85
+ end
86
+
87
+ context 'multiple worksheets with row limit for each' do
88
+ before do
89
+ exl.for_sheet(1).max_rows(40)
90
+ exl.on_row(5..100).columns(4..20).run { |data, row_num| hook1.call(data, row_num) }
91
+ exl.for_sheet(2).max_rows(20)
92
+ exl.on_row(5..100).columns(4..20).run { |data, row_num| hook2.call(data, row_num) }
93
+ end
94
+ it 'calls the hooks correctly' do
95
+ hook1.should_receive(:call).exactly(36).times
96
+ hook2.should_receive(:call).exactly(16).times
97
+ expect(exl.start).to eq ['sheet1', 'sheet2']
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ module ExcelWalker
4
+ describe Reader do
5
+ describe '.create' do
6
+ before { Reader::Reader.stub(new: :reader) }
7
+ it 'should create a new instance of writer' do
8
+ expect(Reader.create('path')).to eq :reader
9
+ end
10
+ end
11
+ end
12
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ module ExcelWalker
4
+ describe Writer do
5
+ describe '.create' do
6
+ before { Writer::Writer.stub(new: :writer) }
7
+ it 'should create a new instance of writer' do
8
+ expect(Writer.create('path')).to eq :writer
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter File.expand_path('../../spec', __FILE__)
5
+ end
6
+ end
7
+
8
+ # Modify load path so you can require it directly.
9
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
10
+
11
+ # show bundle install message if dependencies not met.
12
+ require 'bundler/setup'
13
+
14
+ # This will require me all the gems automatically for the groups. If I do only .setup then I will have to require gems
15
+ # manually. Note that you have still have to require some gems if they are part of bigger gem like ActiveRecord which is
16
+ # part of Rails. You can say :require => false in gemfile to always use explicit requiring
17
+ Bundler.require(:default, :test)
18
+
19
+ require 'excel_walker'
20
+
21
+ # This file was generated by the `rspec --init` command. Conventionally, all
22
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
23
+ # Require this file using `require "spec_helper"` to ensure that it is only
24
+ # loaded once.
25
+ #
26
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
27
+ RSpec.configure do |config|
28
+ config.treat_symbols_as_metadata_keys_with_true_values = true
29
+ config.run_all_when_everything_filtered = true
30
+ config.filter_run :focus
31
+
32
+ # Run specs in random order to surface order dependencies. If you find an
33
+ # order dependency and want to debug it, you can fix the order by providing
34
+ # the seed, which is printed after each run.
35
+ # --seed 1234
36
+ config.order = 'random'
37
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: excel_walker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shadab Ahmed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: creek
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: axlsx
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>'
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>'
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
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
+ description: A declarative parser and builder for Excel Files
84
+ email:
85
+ - shadab.ansari@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .idea/.name
92
+ - .idea/.rakeTasks
93
+ - .idea/dictionaries/shadab.xml
94
+ - .idea/encodings.xml
95
+ - .idea/excel_walker.iml
96
+ - .idea/misc.xml
97
+ - .idea/modules.xml
98
+ - .idea/scopes/scope_settings.xml
99
+ - .idea/vcs.xml
100
+ - .idea/workspace.xml
101
+ - .rspec
102
+ - .travis.yml
103
+ - Gemfile
104
+ - Guardfile
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - excel_walker.gemspec
109
+ - lib/excel_walker.rb
110
+ - lib/excel_walker/errors.rb
111
+ - lib/excel_walker/reader.rb
112
+ - lib/excel_walker/reader/hook.rb
113
+ - lib/excel_walker/reader/reader.rb
114
+ - lib/excel_walker/version.rb
115
+ - lib/excel_walker/writer.rb
116
+ - lib/excel_walker/writer/cells.rb
117
+ - lib/excel_walker/writer/hook.rb
118
+ - lib/excel_walker/writer/sheet_builder.rb
119
+ - spec/excel_walker/reader/hook_spec.rb
120
+ - spec/excel_walker/reader/reader_spec.rb
121
+ - spec/excel_walker/reader_spec.rb
122
+ - spec/excel_walker/writer/cells_spec.rb
123
+ - spec/excel_walker/writer/hook_spec.rb
124
+ - spec/excel_walker/writer/sheet_builder_spec.rb
125
+ - spec/excel_walker/writer_spec.rb
126
+ - spec/spec_helper.rb
127
+ homepage: https://github.com/shadabahmed/excel_walker
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.1.4
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: This gem chooses a different approach to Excel Parsing since excel can contain
151
+ many regions of interest.
152
+ test_files:
153
+ - spec/excel_walker/reader/hook_spec.rb
154
+ - spec/excel_walker/reader/reader_spec.rb
155
+ - spec/excel_walker/reader_spec.rb
156
+ - spec/excel_walker/writer/cells_spec.rb
157
+ - spec/excel_walker/writer/hook_spec.rb
158
+ - spec/excel_walker/writer/sheet_builder_spec.rb
159
+ - spec/excel_walker/writer_spec.rb
160
+ - spec/spec_helper.rb