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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19940731a3d60be4f0f8f4304585f8c36b4855b9
4
- data.tar.gz: 0745972f955570f622ebf25b0f89c2cfa253430d
3
+ metadata.gz: 40c596ee10197b5bc146e4f6be9f2b32ac7a06f7
4
+ data.tar.gz: 34c2cfdaae3582ffe47b557bbef408dcbddf434b
5
5
  SHA512:
6
- metadata.gz: 504b261f043af26e1fc4a055ab8c18d8f943809eaad2cea83e99271c415274bd88104558c9374832f43077bd8e2589e83bf35a53aa09c60bee5e8620872b12c2
7
- data.tar.gz: 05ca9a4818c5d544cfaa6233d20e607192d1d132a221e33ebc4971a24d6aba0dd6f55b97d3679b9d3724eb2fc9086cf76eff288270c52cb9fba8616908a4ed45
6
+ metadata.gz: 9a3dd614fe5fbaa9567eaec7687efb35a3545cede5e90a12925b6f8e9f2995164847f4cee19330b4831844c2cde34c566de5a2d961d60ebfe9a62e1f2732fc85
7
+ data.tar.gz: b2f60c6c5592bb357214bf387cbb94fd12f0d320d80ab7022113b3d679c2c96d611f103a6ea4f94501da61eae8f387bb17d3c844834c2e455214f4e21fa09894
@@ -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 false
239
+ # Removes all Rows (omitting headers) where the block is falsey
240
240
  #
241
- # @param [String] header the header of the Column to pass to the block
242
- # @yield [Object] the value at the intersection of Column and Row
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!( header )
246
+ def filter!( *headers )
247
247
  hrows = sheet.header_rows
248
- idx = index_by_header( header )
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
- Win32::Registry::HKEY_CURRENT_USER.open( 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders' )['Personal'] rescue Dir.pwd.gsub('/','\\')
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
- wb = excel.workbooks.open({'filename'=> other, 'readOnly' => true})
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
@@ -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 false
284
+ # Removes all Rows (omitting headers) where the block is falsey
283
285
  #
284
- # @param [String] header the header of the Column to pass to the block
285
- # @yield [Object] the value at the intersection of Column and Row
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!( header, &block )
290
- return to_enum( :filter!, header ) unless block_given?
291
- data.filter!( header, &block ); self
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 { |s| self =~ s.to_s }
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=nil )
91
+ def add( ref = false )
79
92
  case ref
80
- when nil ; s = Sheet.new( 'Sheet' + ( @sheets.count + 1 ).to_s, self )
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(m, *args, &block)
162
- if ExcelToolsMethods.include?( m )
174
+ def method_missing(method, *args, &block)
175
+ if ExcelToolsMethods.include?( method )
163
176
  require_relative 'rubyexcel/excel_tools.rb'
164
- send( m, *args, &block )
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?( m )
175
- if ExcelToolsMethods.include?( m )
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
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-09-30 00:00:00.000000000 Z
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.0.4
51
+ rubygems_version: 2.1.5
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: Spreadsheets in Ruby