rubyexcel 0.3.6 → 0.3.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e73dc9173659b6318a48416b5a6692a0d8b5affa
4
- data.tar.gz: 379dfddff3355e9cac9681f374fd85d8a9134136
3
+ metadata.gz: 75b8ea393ff09d58583bf303db48f20701f1497a
4
+ data.tar.gz: 4ff035e0b2044679f01e555954e584654b3d199c
5
5
  SHA512:
6
- metadata.gz: 90d1297aaf058a85e9ad8abaa646fa00a5c4cdeb29048826629f91d5f34116f3d274b5c06b0cd942374103bda43738581a298cb5b9b0114d88746a2347e016bb
7
- data.tar.gz: a7ecbc87bd8fc4ae4633a99f89d8075caab55641b75a6802760bedf7dada3809f257e5357af84404dbcf9b26bb80b4d09058ee6914d44267c47ac1b2389d745a
6
+ metadata.gz: c5f31688394d7a8ea42142736bb2768019c5850af22da19ca4b1e1bd7e327f74e7a94a8fb9dc3cc6b9be8540eb86ebc36328a294fc9b28ef9b65e5a545c1ae40
7
+ data.tar.gz: 3eb3b05e1913bc75ef784b46f61100358528119e50511dc20f5b62375ead84106839ab05761920813419615fae6186f5d77cbfb4fe561d490dc24e917bbd402b
data/README.md CHANGED
@@ -235,6 +235,7 @@ wb.delete( 1 )
235
235
  wb.delete( 'Sheet1' )
236
236
  wb.delete( sheet1 )
237
237
  wb.delete( /sheet1/i )
238
+ wb.delete { |sht| sht.name == 'Sheet1' }
238
239
 
239
240
  #Import a WIN32OLE Workbook or Sheet, either by passing the Object or a Filename
240
241
  #Parameters: WIN32OLE Object or Filename, SheetName or nil for all Sheets, true to keep Excel Formulas or omit to import Values.
data/lib/rubyexcel.rb CHANGED
@@ -112,11 +112,16 @@ module RubyExcel
112
112
  #
113
113
  # Removes Sheet(s) from the Workbook
114
114
  #
115
- # @param [Fixnum, String, Regexp, RubyExcel::Sheet] ref the reference or object to remove
115
+ # @param [Fixnum, String, Regexp, RubyExcel::Sheet, NilClass] ref the reference or object to remove, or nil if passing a block
116
+ # @yield [RubyExcel::Sheet] yields each sheet, if there is no argument and a block is given
116
117
  #
117
118
 
118
- def delete( ref )
119
+ def delete( ref=nil, &block )
120
+
121
+ fail ArgumentError, 'Requires either an argument OR a block' if ref && block_given?
122
+
119
123
  case ref
124
+ when nil ; @sheets.reject! { |sht| yield sht }
120
125
  when Fixnum ; @sheets.delete_at( ref - 1 )
121
126
  when String ; @sheets.reject! { |s| s.name == ref }
122
127
  when Regexp ; @sheets.reject! { |s| s.name =~ ref }
@@ -247,13 +247,8 @@ module RubyExcel
247
247
  #
248
248
 
249
249
  def to_safe_format!
250
- sheets { |s| s.rows { |r| r.map! { |v|
251
- if v.is_a?( String )
252
- v[0] == '=' ? v.sub( /\A=/,"'=" ) : v
253
- else
254
- v.to_s
255
- end
256
- } } }; self
250
+ sheets &:to_safe_format!
251
+ self
257
252
  end
258
253
 
259
254
  end # Workbook
@@ -542,6 +542,9 @@ module RubyExcel
542
542
  sort_method = lambda { |array| idx_array.map { |idx| array[idx] } }
543
543
  data.sort_by!( &sort_method )
544
544
  self
545
+ rescue ArgumentError => err
546
+ raise( NoMethodError, 'Item not comparable in "' + headers.flatten.map(&:to_s).join(', ') + '"' ) if err.message == 'comparison of Array with Array failed'
547
+ raise err
545
548
  end
546
549
 
547
550
  #
@@ -638,6 +641,27 @@ module RubyExcel
638
641
  data.map { |ar| ar.map { |v| v.to_s.gsub(/\t|\n|\r/,' ') }.join "\t" }.join( $/ )
639
642
  end
640
643
 
644
+ # {Sheet#to_safe_format!}
645
+
646
+ def to_safe_format
647
+ dup.to_safe_format!
648
+ end
649
+
650
+ #
651
+ # Standardise the data for safe export to Excel.
652
+ # Set each cell contents to a string and remove leading equals signs.
653
+ #
654
+
655
+ def to_safe_format!
656
+ rows { |r| r.map! { |v|
657
+ if v.is_a?( String )
658
+ v[0] == '=' ? v.sub( /\A=/,"'=" ) : v
659
+ else
660
+ v.to_s
661
+ end
662
+ } }; self
663
+ end
664
+
641
665
  #
642
666
  # the Sheet as a TSV String
643
667
  #
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyexcel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
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-08 00:00:00.000000000 Z
11
+ date: 2013-12-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A tabular data structure in Ruby, with header-based helper methods for
14
- analysis and editing, and some of Excel's API style. Can output as 2D Array, HTML,
15
- CSV, TSV, or an Excel WIN32OLE Object
14
+ analysis and editing, and some of Excel's API style. Can output as 2D Array, HTML
15
+ Table, CSV, TSV, or an Excel WIN32OLE Object
16
16
  email: VirtuosoJoel@gmail.com
17
17
  executables: []
18
18
  extensions: []