rubyexcel 0.1.3 → 0.1.4

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.
Files changed (3) hide show
  1. data/lib/README.md +15 -4
  2. data/lib/rubyexcel/sheet.rb +6 -14
  3. metadata +3 -3
data/lib/README.md CHANGED
@@ -130,9 +130,6 @@ s.column( 'A' ) #=> Column
130
130
  s.column( 1 ) #=> Column
131
131
  ```
132
132
 
133
- Some Examples
134
- ========
135
-
136
133
  Common Operations
137
134
  --------
138
135
 
@@ -153,12 +150,25 @@ s.rows(2) { |row| row << x; x+=1 }
153
150
  #Filter to specific part numbers
154
151
  s.filter!( 'Part', &/Type[1-3]/ )
155
152
 
153
+ #Sort by Part Number
154
+ s.sort_by!( 'Part' )
155
+
156
156
  #Add the Number to the Cost in each row.
157
157
  s.rows(2) { |row| row.cell_h('Cost').value += row.cell_h('Number').value }
158
158
 
159
159
  #Split the data into multiple sheets by part number
160
160
  wb = s.split( 'Part' )
161
161
 
162
+ #Open a sheet in an Excel Workbook
163
+ #Output a sheet as a TSV file
164
+ File.write( 'Output.txt', wb.sheets(1).to_s )
165
+
166
+ #Output a sheet as an HTML page
167
+ File.write( 'Output.htm', wb.sheets(2).to_html )
168
+
169
+ #Open a sheet in an Excel Workbook
170
+ wb.sheets( 'Type3' ).to_excel
171
+
162
172
  ```
163
173
 
164
174
  Workbook
@@ -292,8 +302,9 @@ type_1_and_3, other = s.partition( 'Part', &/Type[13]/ )
292
302
  s.reverse_rows!
293
303
  s.reverse_columns!
294
304
 
295
- #Sort the rows by a header (ignores header rows)
305
+ #Sort the rows by header(s) (ignores header rows)
296
306
  s.sort_by!( 'Part' )
307
+ s.sort_by!( 'Qty', 'Part' )
297
308
 
298
309
  #Split a Sheet into a Workbook of Sheets by a column (selected by header)
299
310
  wb = s.split( 'Part' )
@@ -36,7 +36,7 @@ module RubyExcel
36
36
  def initialize( name, workbook )
37
37
  @workbook = workbook
38
38
  @name = name
39
- @header_rows = nil
39
+ @header_rows = 1
40
40
  @data = Data.new( self, [[]] )
41
41
  end
42
42
 
@@ -458,23 +458,15 @@ module RubyExcel
458
458
  alias each rows
459
459
 
460
460
  #
461
- # Sort the data according to a block (avoiding headers)
461
+ # Sort the data by a column, selected by header(s)
462
462
  #
463
-
464
- def sort!( &block )
465
- data.sort!( &block ); self
466
- end
467
-
468
- #
469
- # Sort the data by a column, selected by header
470
- #
471
- # @param [String] header the header to sort the Sheet by
463
+ # @param [String, Array<String>] headers the header(s) to sort the Sheet by
472
464
  #
473
465
 
474
- def sort_by!( header )
466
+ def sort_by!( *headers )
475
467
  raise ArgumentError, 'Sheet#sort_by! does not support blocks.' if block_given?
476
- idx = data.index_by_header( header ) - 1
477
- sort_method = lambda { |array| array[idx] }
468
+ idx_array = headers.flatten.map { |header| data.index_by_header( header ) - 1 }
469
+ sort_method = lambda { |array| idx_array.map { |idx| array[idx] } }
478
470
  data.sort_by!( &sort_method )
479
471
  self
480
472
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyexcel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
12
+ date: 2013-05-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A tabular data structure in Ruby, with header-based helper methods and
15
- some of Excel's API style.
15
+ some of Excel's API style. Designed for Windows + Excel.
16
16
  email: VirtuosoJoel@gmail.com
17
17
  executables: []
18
18
  extensions: []