roo 2.3.0 → 2.3.1

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: f9b79f7270fb925c4aa402c0bd1bcccfc422ac92
4
- data.tar.gz: f5ed3e4155c09890a710265c3a31e308ec4660fa
3
+ metadata.gz: cd058c382f97cefc8605bb1fdf40a2900312d6bc
4
+ data.tar.gz: 4a62144cc33be58fbab07eababe5d6e8a6205c30
5
5
  SHA512:
6
- metadata.gz: bb21c71a0343bcce335b4ddc7b5b0caec8ba69d5059e09868e76a7494338fd11bd8d6dae0c0697dbc2ccef4564f7fa19ae56cc09b1c6bca22a6670b7ee1ada6c
7
- data.tar.gz: 4563b478a1a0c71fbd7087097917b4eacc0a744d8f3d806ce02f8836b767f34a16c40e3207695180ff1a9882f74a6c9c6b354f84547fee5e91a0bf08959ff04a
6
+ metadata.gz: 626854d9aea329f2f2113a1fba53d9981d09ccb520c5ffec06936f996f786874a2b437e3fb1125151f4c3c2248006f3b6ca4fc1e6ddb758e96b36c4ebcbe08d1
7
+ data.tar.gz: 1432ebdeef169aad8eb64982c612da9cff907743a2512b594ded3ebff2823428a10e9ec1a326561ab6e0c68d9bdb39b1abe15655e797304df51dde68e89e437b
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 2.1
5
- - 2.2.0
4
+ - 2.1.8
5
+ - 2.2.4
6
6
  - ruby-head
7
7
  - jruby-19mode # JRuby in 1.9 mode
8
8
  - rbx-2
@@ -1,3 +1,12 @@
1
+ ## [2.3.1] - 2015-01-08
2
+ ### Fixed
3
+ - Properly parse sci-notation number like 1E-3 [#288](https://github.com/roo-rb/roo/pull/288)
4
+ - Include all tests in default rake run [#283](https://github.com/roo-rb/roo/pull/283)
5
+ - Fix zero-padded numbers for Excelx [#282](https://github.com/roo-rb/roo/pull/282)
6
+
7
+ ### Changed
8
+ - Moved `ERROR_VALUES` from Excelx::Cell::Number ~> Excelx. [#280](https://github.com/roo-rb/roo/pull/280)
9
+
1
10
  ## [2.3.0] - 2015-12-10
2
11
  ### Changed
3
12
  - Excelx::Cell::Number will return a String instead of an Integer or Float if the cell has an error like #DIV/0, etc. [#273](https://github.com/roo-rb/roo/pull/273)
data/README.md CHANGED
@@ -189,6 +189,9 @@ xlsx.cell(3, 'C')
189
189
  # => 600000383.0
190
190
 
191
191
  xlsx.excelx_value(row,col)
192
+ # => '600000383'
193
+
194
+ xlsx.formatted_value(row,col)
192
195
  # => '0600000383'
193
196
  ```
194
197
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'coveralls/rake/task'
7
7
  # Test unit
8
8
  Rake::TestTask.new do |t|
9
9
  t.libs << 'test'
10
- t.test_files = FileList['test/test*.rb']
10
+ t.test_files = FileList['test/**/test*.rb']
11
11
  t.verbose = true
12
12
  end
13
13
 
@@ -6,8 +6,11 @@ require 'forwardable'
6
6
 
7
7
  module Roo
8
8
  class Excelx < Roo::Base
9
+ require 'set'
9
10
  extend Forwardable
10
11
 
12
+ ERROR_VALUES = %w(#N/A #REF! #NAME? #DIV/0! #NULL! #VALUE! #NUM!).to_set
13
+
11
14
  require 'roo/excelx/shared'
12
15
  require 'roo/excelx/workbook'
13
16
  require 'roo/excelx/shared_strings'
@@ -194,6 +197,13 @@ module Roo
194
197
  safe_send(sheet_for(sheet).cells[key], :cell_value)
195
198
  end
196
199
 
200
+ # returns the internal value of an excelx cell
201
+ # Note: this is only available within the Excelx class
202
+ def formatted_value(row, col, sheet = nil)
203
+ key = normalize(row, col)
204
+ safe_send(sheet_for(sheet).cells[key], :formatted_value)
205
+ end
206
+
197
207
  # returns the internal format of an excel cell
198
208
  def excelx_format(row, col, sheet = nil)
199
209
  key = normalize(row, col)
@@ -2,8 +2,6 @@ module Roo
2
2
  class Excelx
3
3
  class Cell
4
4
  class Number < Cell::Base
5
- ERROR_VALUES = %w(#N/A #REF! #NAME? #DIV/0! #NULL! #VALUE! #NUM!)
6
-
7
5
  attr_reader :value, :formula, :format, :cell_value, :link, :coordinate
8
6
 
9
7
  def initialize(value, formula, excelx_type, style, link, coordinate)
@@ -16,24 +14,25 @@ module Roo
16
14
  end
17
15
 
18
16
  def create_numeric(number)
19
- return number if ERROR_VALUES.include?(number)
20
-
17
+ return number if Excelx::ERROR_VALUES.include?(number)
21
18
  case @format
22
19
  when /%/
23
20
  Float(number)
24
21
  when /\.0/
25
22
  Float(number)
26
23
  else
27
- number.include?('.') ? Float(number) : Integer(number)
24
+ (number.include?('.') || (/\A\d+E[-+]\d+\z/i =~ number)) ? Float(number) : Integer(number)
28
25
  end
29
26
  end
30
27
 
31
28
  def formatted_value
32
- return @cell_value if ERROR_VALUES.include?(@cell_value)
29
+ return @cell_value if Excelx::ERROR_VALUES.include?(@cell_value)
33
30
 
34
31
  formatter = formats[@format]
35
32
  if formatter.is_a? Proc
36
33
  formatter.call(@cell_value)
34
+ elsif zero_padded_number?
35
+ "%0#{@format.size}d"% @cell_value
37
36
  else
38
37
  Kernel.format(formatter, @cell_value)
39
38
  end
@@ -80,6 +79,12 @@ module Roo
80
79
  '@' => proc { |number| number }
81
80
  }
82
81
  end
82
+
83
+ private
84
+
85
+ def zero_padded_number?
86
+ @format[/0+/] == @format
87
+ end
83
88
  end
84
89
  end
85
90
  end
@@ -1,3 +1,3 @@
1
1
  module Roo
2
- VERSION = '2.3.0'
2
+ VERSION = '2.3.1'
3
3
  end
@@ -6,6 +6,18 @@ describe Roo::Excelx do
6
6
  Roo::Excelx.new(path)
7
7
  end
8
8
 
9
+ describe 'Constants' do
10
+ describe 'ERROR_VALUES' do
11
+ it 'returns all possible errorr values' do
12
+ expect(described_class::ERROR_VALUES).to eq(%w(#N/A #REF! #NAME? #DIV/0! #NULL! #VALUE! #NUM!).to_set)
13
+ end
14
+
15
+ it 'is a set' do
16
+ expect(described_class::ERROR_VALUES).to be_an_instance_of(Set)
17
+ end
18
+ end
19
+ end
20
+
9
21
  describe '.new' do
10
22
  let(:path) { 'test/files/numeric-link.xlsx' }
11
23
 
@@ -283,6 +295,16 @@ describe Roo::Excelx do
283
295
  end
284
296
  end
285
297
 
298
+ describe '#formatted_value' do
299
+ context 'contains zero-padded numbers' do
300
+ let(:path) { 'test/files/zero-padded-number.xlsx' }
301
+
302
+ it 'returns a zero-padded number' do
303
+ expect(subject.formatted_value(4, 1)).to eq '05010'
304
+ end
305
+ end
306
+ end
307
+
286
308
  describe '#excelx_format' do
287
309
  let(:path) { 'test/files/style.xlsx' }
288
310
 
@@ -1,5 +1,4 @@
1
- require 'roo/excelx/cell/base'
2
- require 'roo/link'
1
+ require 'test_helper'
3
2
 
4
3
  class TestRooExcelxCellBase < Minitest::Test
5
4
  def base
@@ -1,6 +1,4 @@
1
- require 'roo/excelx/cell/base'
2
- require 'roo/excelx/cell/boolean'
3
- require 'roo/link'
1
+ require 'test_helper'
4
2
 
5
3
  class TestRooExcelxCellNumber < Minitest::Test
6
4
  def boolean
@@ -1,9 +1,4 @@
1
- require 'date'
2
- require 'roo/excelx/cell/base'
3
- require 'roo/excelx/cell/datetime'
4
- require 'roo/excelx/cell/date'
5
- require 'roo/link'
6
- require 'pry'
1
+ require 'test_helper'
7
2
 
8
3
  class TestRooExcelxCellDate < Minitest::Test
9
4
  def date_cell
@@ -1,7 +1,4 @@
1
- require 'date'
2
- require 'roo/excelx/cell/base'
3
- require 'roo/excelx/cell/datetime'
4
- require 'roo/link'
1
+ require 'test_helper'
5
2
 
6
3
  class TestRooExcelxCellDateTime < Minitest::Test
7
4
  def test_cell_value_is_datetime
@@ -1,5 +1,4 @@
1
- require 'roo/excelx/cell/base'
2
- require 'roo/excelx/cell/empty'
1
+ require 'test_helper'
3
2
 
4
3
  class TestRooExcelxCellEmpty < Minitest::Test
5
4
  def empty
@@ -1,6 +1,4 @@
1
- require 'roo/excelx/cell/base'
2
- require 'roo/excelx/cell/number'
3
- require 'roo/link'
1
+ require 'test_helper'
4
2
 
5
3
  class TestRooExcelxCellNumber < Minitest::Test
6
4
  def number
@@ -17,6 +15,16 @@ class TestRooExcelxCellNumber < Minitest::Test
17
15
  assert_kind_of(Integer, cell.value)
18
16
  end
19
17
 
18
+ def test_scientific_notation
19
+ cell = Roo::Excelx::Cell::Number.new '1.2E-3', nil, ['0'], nil, nil, nil
20
+ assert_kind_of(Float, cell.value)
21
+ end
22
+
23
+ def test_simple_scientific_notation
24
+ cell = Roo::Excelx::Cell::Number.new '1E-3', nil, ['0'], nil, nil, nil
25
+ assert_kind_of(Float, cell.value)
26
+ end
27
+
20
28
  def test_percent
21
29
  cell = Roo::Excelx::Cell::Number.new '42.1', nil, ['0.00%'], nil, nil, nil
22
30
  assert_kind_of(Float, cell.value)
@@ -35,7 +43,7 @@ class TestRooExcelxCellNumber < Minitest::Test
35
43
  end
36
44
 
37
45
  def test_numbers_with_cell_errors
38
- %w(#N/A #REF! #NAME? #DIV/0! #NULL! #VALUE! #NUM!).each do |error|
46
+ Roo::Excelx::ERROR_VALUES.each do |error|
39
47
  cell = Roo::Excelx::Cell::Number.new error, nil, ['General'], nil, nil, nil
40
48
  assert_equal error, cell.value
41
49
  assert_equal error, cell.formatted_value
@@ -1,6 +1,4 @@
1
- require 'roo/excelx/cell/base'
2
- require 'roo/excelx/cell/string'
3
- require 'roo/link'
1
+ require 'test_helper'
4
2
 
5
3
  class TestRooExcelxCellString < Minitest::Test
6
4
  def string
@@ -1,7 +1,4 @@
1
- require 'roo/excelx/cell/base'
2
- require 'roo/excelx/cell/datetime'
3
- require 'roo/excelx/cell/time'
4
- require 'roo/link'
1
+ require 'test_helper'
5
2
 
6
3
  class TestRooExcelxCellTime < Minitest::Test
7
4
  def time
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Preymesser
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-12-10 00:00:00.000000000 Z
15
+ date: 2016-01-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri