roo 2.3.0 → 2.3.1
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 +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +9 -0
- data/README.md +3 -0
- data/Rakefile +1 -1
- data/lib/roo/excelx.rb +10 -0
- data/lib/roo/excelx/cell/number.rb +11 -6
- data/lib/roo/version.rb +1 -1
- data/spec/lib/roo/excelx_spec.rb +22 -0
- data/test/excelx/cell/test_base.rb +1 -2
- data/test/excelx/cell/test_boolean.rb +1 -3
- data/test/excelx/cell/test_date.rb +1 -6
- data/test/excelx/cell/test_datetime.rb +1 -4
- data/test/excelx/cell/test_empty.rb +1 -2
- data/test/excelx/cell/test_number.rb +12 -4
- data/test/excelx/cell/test_string.rb +1 -3
- data/test/excelx/cell/test_time.rb +1 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd058c382f97cefc8605bb1fdf40a2900312d6bc
|
4
|
+
data.tar.gz: 4a62144cc33be58fbab07eababe5d6e8a6205c30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 626854d9aea329f2f2113a1fba53d9981d09ccb520c5ffec06936f996f786874a2b437e3fb1125151f4c3c2248006f3b6ca4fc1e6ddb758e96b36c4ebcbe08d1
|
7
|
+
data.tar.gz: 1432ebdeef169aad8eb64982c612da9cff907743a2512b594ded3ebff2823428a10e9ec1a326561ab6e0c68d9bdb39b1abe15655e797304df51dde68e89e437b
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
data/Rakefile
CHANGED
data/lib/roo/excelx.rb
CHANGED
@@ -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
|
data/lib/roo/version.rb
CHANGED
data/spec/lib/roo/excelx_spec.rb
CHANGED
@@ -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,6 +1,4 @@
|
|
1
|
-
require '
|
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
|
-
|
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
|
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.
|
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:
|
15
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: nokogiri
|