rubyexcel 0.2.7 → 0.2.8

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: bf0e1a049736d39e6beb83295766cb981114ed87
4
- data.tar.gz: 36e194c30416d7839c590c156779f7004f8060ce
3
+ metadata.gz: 05baad4d95550fd8ad617defee125d098768f039
4
+ data.tar.gz: 38bde97de67d3a586ef3b7eab6d00be2e0e98651
5
5
  SHA512:
6
- metadata.gz: f139746e6406e04446a4c46f0817def0c0c9255ec3fba1dd3ceb00d88c6bcb2faf1e72061a7c91878ecdd4fa9277a21d1e63c8a97b29c97a04420322ceed9f89
7
- data.tar.gz: aede6d3279653d0e690dd585bc31cf409c43db272d3ee0bc6718eb68e074f05c69ea2c31fdc8dc721a8f8e05966ed49d2ab2a437ff514861ba607104e07337f3
6
+ metadata.gz: 66b83ff4c9629ffe1a07ea06b7baac4e432a550ee46d15ab3fa884fadf5d713025cbcef52b1a298548793d5a658b7498e8553aece4e6a12fdfe49cd51c06cf36
7
+ data.tar.gz: 5c40988dfe369886aebf048a1e2bf97ce807f97094e76c8dafcafcfd4ddb69075b6028ec33bd168fd898b5a22c20dac5b563a1517ee27f84a404e3f0dd4491e3
data/README.md CHANGED
@@ -193,6 +193,15 @@ wb.sheets( 'Type3' ).to_excel
193
193
  #If you feel the need to delete everything between a set of rows:
194
194
  s.rows(2, 4).reverse_each &:delete
195
195
 
196
+ #Gather text files containing string versions of RubyExcel::Sheet into a Workbook
197
+ wb = RubyExcel::Workbook.new
198
+ Dir.glob( '*.txt' ) do |f|
199
+ data = File.read(f).split($/).map { |r| r.split("\t") }
200
+ s = wb.add( f.chomp('.txt') )
201
+ s.load data
202
+ end
203
+
204
+
196
205
  ```
197
206
 
198
207
  Workbook
@@ -719,4 +728,4 @@ Todo List
719
728
 
720
729
  Copyright (c) 2013, Joel Pearson and Contributors. All Rights Reserved.
721
730
 
722
- This project is licenced under the [MIT License](LICENSE.md).
731
+ This project is licenced under the [MIT License](https://github.com/VirtuosoJoel/RubyExcel/blob/master/LICENSE.md).
@@ -254,8 +254,8 @@ require_relative 'address.rb'
254
254
  headers = headers.flatten
255
255
  hrow = sheet.header_rows - 1
256
256
  ensure_shape
257
- @data = @data.transpose.select{ |col| headers.include?( col[hrow] ) }
258
- @data = @data.sort_by{ |col| headers.index( col[hrow] ) || col[hrow] }.transpose
257
+ @data = @data.transpose.select{ |col| col[0..hrow].any?{ |val| headers.include?( val ) } }
258
+ @data = @data.sort_by{ |col| headers.index( col[0..hrow].select { |val| headers.include?( val ) }.first ) || headers.length }.transpose
259
259
  calc_dimensions
260
260
  end
261
261
 
@@ -419,7 +419,9 @@ require_relative 'address.rb'
419
419
  private
420
420
 
421
421
  def calc_dimensions
422
- @rows, @cols = @data.length, @data.max_by { |row| row.length }.length; self
422
+ @rows = ( @data.length rescue 0 )
423
+ @cols = ( @data.max_by { |row| row.length }.length rescue 0 )
424
+ self
423
425
  end
424
426
 
425
427
  def ensure_shape
@@ -150,7 +150,7 @@ module RubyExcel
150
150
  sht.name = s.name
151
151
  make_sheet_pretty( dump_to_sheet( s.to_a, sht ) )
152
152
  end
153
- wb.sheets(1).select
153
+ wb.sheets(1).select rescue nil
154
154
  wb.application.visible = true unless invisible
155
155
  wb
156
156
  end
@@ -85,7 +85,7 @@ module RubyExcel
85
85
  #
86
86
 
87
87
  def empty?
88
- all? { |val| val.to_s.empty? }
88
+ each_wh.all? { |val| val.to_s.empty? }
89
89
  end
90
90
 
91
91
  #
@@ -277,6 +277,7 @@ module RubyExcel
277
277
  #
278
278
 
279
279
  def filter!( header, &block )
280
+ return to_enum( :filter!, header ) unless block_given?
280
281
  data.filter!( header, &block ); self
281
282
  end
282
283
 
@@ -544,6 +545,14 @@ module RubyExcel
544
545
  data.all
545
546
  end
546
547
 
548
+ #
549
+ # The Sheet as a CSV String
550
+ #
551
+
552
+ def to_csv
553
+ CSV.generate { |csv| to_a.each { |r| csv << r } }
554
+ end
555
+
547
556
  #
548
557
  # The Sheet as a WIN32OLE Excel Workbook
549
558
  # @note This requires Windows and MS Excel
@@ -562,13 +571,21 @@ module RubyExcel
562
571
  end
563
572
 
564
573
  #
565
- # The Sheet as a Tab Seperated Value String
574
+ # The Sheet as a Tab Seperated Value String (Strips extra whitespace)
566
575
  #
567
576
 
568
577
  def to_s
569
578
  data.map { |ar| ar.map { |v| v.to_s.gsub(/\t|\n|\r/,' ') }.join "\t" }.join( $/ )
570
579
  end
571
580
 
581
+ #
582
+ # the Sheet as a TSV String
583
+ #
584
+
585
+ def to_tsv
586
+ CSV.generate( :col_sep => "\t" ) { |csv| to_a.each { |r| csv << r } }
587
+ end
588
+
572
589
  #
573
590
  # Remove any Rows with duplicate values within a Column
574
591
  #
data/lib/rubyexcel.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative 'rubyexcel/rubyexcel_components.rb'
2
2
  require 'cgi'
3
+ require 'csv'
3
4
 
4
5
  #
5
6
  # Ruby's standard Regexp class.
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.2.7
4
+ version: 0.2.8
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-06-06 00:00:00.000000000 Z
11
+ date: 2013-08-22 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, Excel,
@@ -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.2
51
+ rubygems_version: 2.0.4
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: Spreadsheets in Ruby