rubyexcel 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubyexcel/data.rb +6 -6
- data/lib/rubyexcel/excel_tools.rb +18 -2
- data/lib/rubyexcel/sheet.rb +9 -7
- data/lib/rubyexcel.rb +21 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40c596ee10197b5bc146e4f6be9f2b32ac7a06f7
|
4
|
+
data.tar.gz: 34c2cfdaae3582ffe47b557bbef408dcbddf434b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a3dd614fe5fbaa9567eaec7687efb35a3545cede5e90a12925b6f8e9f2995164847f4cee19330b4831844c2cde34c566de5a2d961d60ebfe9a62e1f2732fc85
|
7
|
+
data.tar.gz: b2f60c6c5592bb357214bf387cbb94fd12f0d320d80ab7022113b3d679c2c96d611f103a6ea4f94501da61eae8f387bb17d3c844834c2e455214f4e21fa09894
|
data/lib/rubyexcel/data.rb
CHANGED
@@ -236,17 +236,17 @@ require_relative 'address.rb'
|
|
236
236
|
end
|
237
237
|
|
238
238
|
#
|
239
|
-
# Removes all Rows (omitting headers) where the block is
|
239
|
+
# Removes all Rows (omitting headers) where the block is falsey
|
240
240
|
#
|
241
|
-
# @param [String]
|
242
|
-
# @yield [
|
241
|
+
# @param [String, Array] headers splat of the headers for the Columns to filter by
|
242
|
+
# @yield [Array] the values at the intersections of Column and Row
|
243
243
|
# @return [self]
|
244
244
|
#
|
245
245
|
|
246
|
-
def filter!(
|
246
|
+
def filter!( *headers )
|
247
247
|
hrows = sheet.header_rows
|
248
|
-
|
249
|
-
@data = @data.select.with_index { |row, i| hrows > i || yield( row[ idx -1 ] ) }
|
248
|
+
idx_array = headers.flatten.map { |header| index_by_header( header ) }.compact
|
249
|
+
@data = @data.select.with_index { |row, i| hrows > i || yield( idx_array.map { |idx| row[ idx -1 ] } ) }
|
250
250
|
calc_dimensions
|
251
251
|
end
|
252
252
|
|
@@ -27,6 +27,16 @@ module RubyExcel
|
|
27
27
|
range
|
28
28
|
end
|
29
29
|
|
30
|
+
#
|
31
|
+
# Find the Windows "Documents" or "My Documents" path, or return the present working directory if it can't be found.
|
32
|
+
#
|
33
|
+
# @return [String]
|
34
|
+
#
|
35
|
+
|
36
|
+
def self.documents_path
|
37
|
+
Win32::Registry::HKEY_CURRENT_USER.open( 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders' )['Personal'] rescue Dir.pwd.gsub('/','\\')
|
38
|
+
end
|
39
|
+
|
30
40
|
class Workbook
|
31
41
|
|
32
42
|
|
@@ -50,7 +60,7 @@ module RubyExcel
|
|
50
60
|
#
|
51
61
|
|
52
62
|
def documents_path
|
53
|
-
|
63
|
+
RubyExcel.documents_path
|
54
64
|
end
|
55
65
|
|
56
66
|
#
|
@@ -116,7 +126,13 @@ module RubyExcel
|
|
116
126
|
#Open the file with Excel
|
117
127
|
excel = WIN32OLE.new( 'excel.application' )
|
118
128
|
excel.displayalerts = false
|
119
|
-
|
129
|
+
|
130
|
+
begin
|
131
|
+
wb = excel.workbooks.open({'filename'=> other, 'readOnly' => true})
|
132
|
+
rescue WIN32OLERuntimeError
|
133
|
+
excel.quit
|
134
|
+
raise
|
135
|
+
end
|
120
136
|
|
121
137
|
# Only one sheet, or the entire Workbook?
|
122
138
|
if sheetname
|
data/lib/rubyexcel/sheet.rb
CHANGED
@@ -115,6 +115,7 @@ module RubyExcel
|
|
115
115
|
self
|
116
116
|
end
|
117
117
|
|
118
|
+
# @deprecated Please use {#filter!} instead
|
118
119
|
# @overload advanced_filter!( header, comparison_operator, search_criteria, ... )
|
119
120
|
# Filter on multiple criteria
|
120
121
|
# @param [String] header a header to search under
|
@@ -129,6 +130,7 @@ module RubyExcel
|
|
129
130
|
#
|
130
131
|
|
131
132
|
def advanced_filter!( *args )
|
133
|
+
warn "[DEPRECATION] `advanced_filter!` is deprecated. Please use `filter!` instead."
|
132
134
|
data.advanced_filter!( *args ); self
|
133
135
|
end
|
134
136
|
|
@@ -279,16 +281,16 @@ module RubyExcel
|
|
279
281
|
end
|
280
282
|
|
281
283
|
#
|
282
|
-
# Removes all Rows (omitting headers) where the block is
|
284
|
+
# Removes all Rows (omitting headers) where the block is falsey
|
283
285
|
#
|
284
|
-
# @param [String]
|
285
|
-
# @yield [
|
286
|
+
# @param [String, Array] headers splat of the headers for the Columns to filter by
|
287
|
+
# @yield [Array] the values at the intersections of Column and Row
|
286
288
|
# @return [self]
|
287
289
|
#
|
288
290
|
|
289
|
-
def filter!(
|
290
|
-
return to_enum( :filter!,
|
291
|
-
data.filter!(
|
291
|
+
def filter!( *headers, &block )
|
292
|
+
return to_enum( :filter!, headers ) unless block_given?
|
293
|
+
data.filter!( headers, &block ); self
|
292
294
|
end
|
293
295
|
|
294
296
|
#
|
@@ -427,7 +429,7 @@ module RubyExcel
|
|
427
429
|
# Allow for certain method_missing calls
|
428
430
|
#
|
429
431
|
|
430
|
-
def respond_to?( m )
|
432
|
+
def respond_to?( m, include_private = false )
|
431
433
|
|
432
434
|
if m[-1] != '!' && respond_to?( m.to_s + '!' )
|
433
435
|
true
|
data/lib/rubyexcel.rb
CHANGED
@@ -16,7 +16,7 @@ class Regexp
|
|
16
16
|
#
|
17
17
|
|
18
18
|
def to_proc
|
19
|
-
proc { |
|
19
|
+
proc { |string| self =~ string.to_s }
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -26,6 +26,19 @@ end
|
|
26
26
|
|
27
27
|
module RubyExcel
|
28
28
|
|
29
|
+
#
|
30
|
+
# Don't require Windows-specific libraries unless the relevant methods are called
|
31
|
+
#
|
32
|
+
|
33
|
+
def self.method_missing( method, *args, &block )
|
34
|
+
if method == :documents_path
|
35
|
+
require_relative 'rubyexcel/excel_tools.rb'
|
36
|
+
send( method, *args, &block )
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
29
42
|
#
|
30
43
|
# A Workbook which can hold multiple Sheets
|
31
44
|
#
|
@@ -75,9 +88,9 @@ module RubyExcel
|
|
75
88
|
# @param [nil, RubyExcel::Sheet, String] ref the identifier or Sheet to add
|
76
89
|
# @return [RubyExcel::Sheet] the Sheet which was added
|
77
90
|
|
78
|
-
def add( ref=
|
91
|
+
def add( ref = false )
|
79
92
|
case ref
|
80
|
-
when
|
93
|
+
when false ; s = Sheet.new( 'Sheet' + ( @sheets.count + 1 ).to_s, self )
|
81
94
|
when Sheet ; ( s = ref ).workbook = self
|
82
95
|
when String ; s = Sheet.new( ref, self )
|
83
96
|
else ; fail TypeError, "Unsupported Type: #{ ref.class }"
|
@@ -158,10 +171,10 @@ module RubyExcel
|
|
158
171
|
# Don't require Windows-specific libraries unless the relevant methods are called
|
159
172
|
#
|
160
173
|
|
161
|
-
def method_missing(
|
162
|
-
if ExcelToolsMethods.include?(
|
174
|
+
def method_missing(method, *args, &block)
|
175
|
+
if ExcelToolsMethods.include?( method )
|
163
176
|
require_relative 'rubyexcel/excel_tools.rb'
|
164
|
-
send(
|
177
|
+
send( method, *args, &block )
|
165
178
|
else
|
166
179
|
super
|
167
180
|
end
|
@@ -171,8 +184,8 @@ module RubyExcel
|
|
171
184
|
# Allow for certain method_missing calls
|
172
185
|
#
|
173
186
|
|
174
|
-
def respond_to?(
|
175
|
-
if ExcelToolsMethods.include?(
|
187
|
+
def respond_to?( method, include_private = false )
|
188
|
+
if ExcelToolsMethods.include?( method )
|
176
189
|
true
|
177
190
|
else
|
178
191
|
super
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyexcel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Pearson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A tabular data structure in Ruby, with header-based helper methods for
|
14
14
|
analysis and editing, and some of Excel's API style. Can output as 2D Array, HTML,
|
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
48
|
version: '0'
|
49
49
|
requirements: []
|
50
50
|
rubyforge_project:
|
51
|
-
rubygems_version: 2.
|
51
|
+
rubygems_version: 2.1.5
|
52
52
|
signing_key:
|
53
53
|
specification_version: 4
|
54
54
|
summary: Spreadsheets in Ruby
|