spreadsheet 1.0.8 → 1.0.9

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: efb204081ff8ae0e590f3c0537917c622c49f8b4
4
- data.tar.gz: 7b43d12d03e7c40866f63dd86868a1cd29126456
3
+ metadata.gz: f644ff72e11b9264344a7fa3b882bfc2cc36c67c
4
+ data.tar.gz: 9c76a7e5f862ca3a2706f3ec95f891225acfd1bb
5
5
  SHA512:
6
- metadata.gz: 0314b39548f389e90a5441260a591b15038ff43f8c7df34491bc0d6d0c9b89640ace9f52374aa5d5ad52a14211932d53ecc368951221f5839d14bd24a64d4663
7
- data.tar.gz: ce05bc3b15029a77df3fb51d3f5fb4187bd1d12fc0ee4a15fe9c47d546ad50b50c2290bc6f94606a4b96207be02b95c5ddbd0b326a8d2822868ca0918b6aab65
6
+ metadata.gz: 1cc27fc0a6b649df6eb051d086a847b56374c029223552da6027f1515fa72c5f22a97f7f3de2d4b8f6e92a812cfa1dc4e415e6f0fb108ea134714a5fc5d9d20c
7
+ data.tar.gz: 128c01ac9eced267751deffdaaa9b50bf7b5a635cea7656a64d05a821c1120377463dc80366092d25940a3f82a7dd64725ad275c0c10b0ec9855b4bfa295e28d
data/.travis.yml CHANGED
@@ -1,12 +1,15 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  before_install:
3
5
  - gem install bundler
4
6
  bundler_args: --binstubs
5
- script: "ruby -w ./test/suite.rb"
7
+ script: "bundle exec ruby test/suite.rb"
6
8
  rvm:
7
9
  - ruby-head
8
10
  - 2.0.0
9
- - 2.1.1
11
+ - 2.2.3
12
+ - 2.1.7
10
13
  - 1.9.3
11
14
  - 1.9.2
12
15
  - 1.8.7
data/GUIDE.md CHANGED
@@ -2,16 +2,17 @@
2
2
  This guide is meant to get you started using Spreadsheet. By the end of it,
3
3
  you should be able to read and write Spreadsheets.
4
4
 
5
-
6
- ## Reading is easy!
7
- First, make sure all that code is loaded:
5
+ Before you can do anything, you first need to make sure all that code is
6
+ loaded:
8
7
 
9
8
  ```ruby
10
9
  require 'spreadsheet'
11
10
  ```
12
11
 
13
- Worksheets come in various Encodings. You need to tell Spreadsheet which
14
- Encoding you want to deal with. The Default is UTF-8
12
+ ## Reading is easy!
13
+
14
+ Worksheets come in various encodings. You need to tell Spreadsheet which
15
+ encoding you want to deal with. The default is UTF-8
15
16
 
16
17
  ```ruby
17
18
  Spreadsheet.client_encoding = 'UTF-8'
@@ -23,13 +24,13 @@ Let's open a workbook:
23
24
  book = Spreadsheet.open '/path/to/an/excel-file.xls'
24
25
  ```
25
26
 
26
- We can either access all the Worksheets in a Workbook...
27
+ We can either access all the worksheets in a workbook...
27
28
 
28
29
  ```ruby
29
30
  book.worksheets
30
31
  ```
31
32
 
32
- ...or access them by index or name (encoded in your client_encoding)
33
+ ...or access them by index or name (encoded in your `client_encoding`).
33
34
 
34
35
  ```ruby
35
36
  sheet1 = book.worksheet 0
@@ -37,8 +38,8 @@ sheet2 = book.worksheet 'Sheet1'
37
38
  ```
38
39
 
39
40
  Now you can either iterate over all rows that contain some data. A call to
40
- Worksheet.each without argument will omit empty rows at the beginning of the
41
- Worksheet:
41
+ `Worksheet.each` without arguments will omit empty rows at the beginning of the
42
+ worksheet:
42
43
 
43
44
  ```ruby
44
45
  sheet1.each do |row|
@@ -46,7 +47,7 @@ sheet1.each do |row|
46
47
  end
47
48
  ```
48
49
 
49
- Or you can tell Worksheet how many rows should be omitted at the beginning.
50
+ Or you can tell a worksheet how many rows should be omitted at the beginning.
50
51
  The following starts at the 3rd row, regardless of whether or not it or the
51
52
  preceding rows contain any data:
52
53
 
@@ -62,17 +63,17 @@ Or you can access rows directly, by their index (0-based):
62
63
  row = sheet1.row(3)
63
64
  ```
64
65
 
65
- To access the values stored in a Row, treat the Row like an Array.
66
+ To access the values stored in a row, treat the row like an array.
66
67
 
67
68
  ```ruby
68
69
  row[0]
69
70
  ```
70
71
 
71
- -> this will return a String, a Float, an Integer, a Formula, a Link or a Date
72
- or DateTime object - or nil if the cell is empty.
72
+ This will return a `String`, a `Float`, an `Integer`, a `Formula`, a `Link` or a `Date`
73
+ or `DateTime` object - or `nil` if the cell is empty.
73
74
 
74
- More information about the formatting of a cell can be found in the Format
75
- with the equivalent index
75
+ More information about the formatting of a cell can be found in the format
76
+ with the equivalent index:
76
77
 
77
78
  ```ruby
78
79
  row.format 2
data/Gemfile CHANGED
@@ -1,6 +1,10 @@
1
1
  source "https://rubygems.org"
2
2
  gem 'ruby-ole'
3
3
 
4
+ if RUBY_VERSION.to_f > 2.0
5
+ gem 'test-unit'
6
+ gem 'minitest'
7
+ end
4
8
  group :development do
5
9
  gem 'hoe', '>= 3.4'
6
10
  end
data/Gemfile.lock CHANGED
@@ -1,14 +1,23 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- hoe (3.7.1)
4
+ hoe (3.14.2)
5
5
  rake (>= 0.8, < 11.0)
6
- rake (10.1.0)
6
+ minitest (5.8.2)
7
+ power_assert (0.2.4)
8
+ rake (10.4.2)
7
9
  ruby-ole (1.2.11.8)
10
+ test-unit (3.1.5)
11
+ power_assert
8
12
 
9
13
  PLATFORMS
10
14
  ruby
11
15
 
12
16
  DEPENDENCIES
13
17
  hoe (>= 3.4)
18
+ minitest
14
19
  ruby-ole
20
+ test-unit
21
+
22
+ BUNDLED WITH
23
+ 1.10.6
data/History.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 1.0.9 / 18.11.2015
2
+
3
+ Author: 545ch4 <s@rprojekt.org>
4
+ Date: Mon Nov 16 10:26:27 2015 +0100
5
+
6
+ * Add smart method compact! to worksheet
7
+ * Use compact! to reduce the number of rows and columns by striping empty one at both ends.
8
+
1
9
  ### 1.0.8 / 20.10.2015
2
10
 
3
11
  commit e9bd1dd34998803b63460f4951e9aa34e569bd8f
data/lib/spreadsheet.rb CHANGED
@@ -45,7 +45,7 @@ module Spreadsheet
45
45
 
46
46
  ##
47
47
  # The version of Spreadsheet you are using.
48
- VERSION = '1.0.8'
48
+ VERSION = '1.0.9'
49
49
 
50
50
  ##
51
51
  # Default client Encoding. Change this value if your application uses a
@@ -311,6 +311,53 @@ module Spreadsheet
311
311
  # FIXME enlarge or dup check
312
312
  @merged_cells.push [start_row, end_row, start_col, end_col]
313
313
  end
314
+
315
+ def compact!
316
+ recalculate_dimensions
317
+
318
+ # detect first non-nil non-empty row if given first row is empty or nil
319
+ if row(@dimensions[0]).empty? || row(@dimensions[0]).compact.join('').empty?
320
+ (@dimensions[0]...@dimensions[1]).each do |i|
321
+ break unless row(i).empty? || row(i).compact.join('').empty?
322
+ @dimensions[0] = i
323
+ end
324
+ end
325
+
326
+ # detect last non-nil non-empty row if given last row is empty or nil
327
+ if row(@dimensions[1] - 1).empty? || row(@dimensions[1] - 1).compact.join('').empty?
328
+ i = @dimensions[1] - 1
329
+ @dimensions[1] = @dimensions[0]
330
+ # divide and conquer
331
+ while(i - @dimensions[1] > 1) do
332
+ if row(i).empty? || row(i).compact.join('').empty?
333
+ i = @dimensions[1] + (((i - @dimensions[1]) + 1) / 2).to_i
334
+ else
335
+ _i = ((i - @dimensions[1]) / 2).to_i + 1
336
+ @dimensions[1] = i
337
+ i = i + _i
338
+ end
339
+ end
340
+ @dimensions[1] = i + 1
341
+ end
342
+
343
+ # detect first non-empty non-nil column if first column is empty or nil
344
+ if (@dimensions[0]..@dimensions[1]).inject(true){|t, j| t && row(j)[@dimensions[2]].nil?}
345
+ (@dimensions[2]..@dimensions[3]).each do |i|
346
+ break unless (@dimensions[0]..@dimensions[1]).inject(true){|t, j| t && (row(j)[i].nil? || row(j)[i].empty?)}
347
+ @dimensions[2] = i
348
+ end
349
+ end
350
+
351
+ # detect last non-empty non-nil column if last column is empty or nil
352
+ if (@dimensions[0]..@dimensions[1]).inject(true){|t, j| t && row(j)[@dimensions[3]].nil?}
353
+ (@dimensions[2]..@dimensions[3]).reverse_each do |i|
354
+ break unless (@dimensions[0]..@dimensions[1]).inject(true){|t, j| t && (row(j)[i].nil? || row(j)[i].empty?)}
355
+ @dimensions[3] = i
356
+ end
357
+ @dimensions[3] = @dimensions[3]
358
+ end
359
+ end
360
+
314
361
  private
315
362
  def index_of_first ary # :nodoc:
316
363
  return unless ary
data/test/integration.rb CHANGED
@@ -1408,6 +1408,37 @@ module Spreadsheet
1408
1408
  book.worksheet(0).row(0)
1409
1409
  end
1410
1410
  end
1411
+
1412
+ def test_compact
1413
+ path = File.join @data, 'test_compact_many_rows.xls'
1414
+ book = Spreadsheet.open path
1415
+ sheets = book.worksheets
1416
+ assert_equal 1, sheets.size
1417
+ sheet = book.worksheet 0
1418
+ assert_instance_of Excel::Worksheet, sheet
1419
+ assert_equal sheet, book.worksheet('Planilha1')
1420
+ assert_equal sheet.dimensions, [0, 65534, 0, 25]
1421
+ sheet.compact!
1422
+ assert_equal sheet.dimensions, [0, 502, 0, 1]
1423
+ path = File.join @data, 'test_sizes.xls'
1424
+ book = Spreadsheet.open path
1425
+ sheet = book.worksheet 0
1426
+ assert_instance_of Excel::Worksheet, sheet
1427
+ assert_equal sheet.dimensions, [1, 38, 1, 15]
1428
+ sheet.compact!
1429
+ assert_equal sheet.dimensions, [1, 3, 1, 3]
1430
+ sheet = book.worksheet 1
1431
+ assert_instance_of Excel::Worksheet, sheet
1432
+ assert_equal sheet.dimensions, [1, 3, 1, 3]
1433
+ sheet.compact!
1434
+ assert_equal sheet.dimensions, [1, 3, 1, 3]
1435
+ sheet = book.worksheet 2
1436
+ assert_instance_of Excel::Worksheet, sheet
1437
+ assert_equal sheet.dimensions, [0, 4, 0, 4]
1438
+ sheet.compact!
1439
+ assert_equal sheet.dimensions, [0, 2, 0, 2]
1440
+ end
1441
+
1411
1442
  private
1412
1443
 
1413
1444
  # Validates the workbook's SST
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaomi Hatakeyama, Zeno R.R. Davatz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-20 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-ole