Skip to content

Commit

Permalink
Merge pull request #280 from kuldeepaggarwal/code-nitpick
Browse files Browse the repository at this point in the history
move `ERROR_VALUES` from Excelx::Cell::Number ~> Excelx
  • Loading branch information
stevendaniels committed Dec 18, 2015
2 parents d9667fc + 5706739 commit 3383085
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

module Roo
class Excelx < Roo::Base
require 'set'
extend Forwardable

ERROR_VALUES = %w(#N/A #REF! #NAME? #DIV/0! #NULL! #VALUE! #NUM!).to_set

require 'roo/excelx/shared'
require 'roo/excelx/workbook'
require 'roo/excelx/shared_strings'
Expand Down
6 changes: 2 additions & 4 deletions lib/roo/excelx/cell/number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module Roo
class Excelx
class Cell
class Number < Cell::Base
ERROR_VALUES = %w(#N/A #REF! #NAME? #DIV/0! #NULL! #VALUE! #NUM!)

attr_reader :value, :formula, :format, :cell_value, :link, :coordinate

def initialize(value, formula, excelx_type, style, link, coordinate)
Expand All @@ -16,7 +14,7 @@ def initialize(value, formula, excelx_type, style, link, coordinate)
end

def create_numeric(number)
return number if ERROR_VALUES.include?(number)
return number if Excelx::ERROR_VALUES.include?(number)

case @format
when /%/
Expand All @@ -29,7 +27,7 @@ def create_numeric(number)
end

def formatted_value
return @cell_value if ERROR_VALUES.include?(@cell_value)
return @cell_value if Excelx::ERROR_VALUES.include?(@cell_value)

formatter = formats[@format]
if formatter.is_a? Proc
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/roo/excelx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
Roo::Excelx.new(path)
end

describe 'Constants' do
describe 'ERROR_VALUES' do
it 'returns all possible errorr values' do
expect(described_class::ERROR_VALUES).to eq(%w(#N/A #REF! #NAME? #DIV/0! #NULL! #VALUE! #NUM!).to_set)
end

it 'is a set' do
expect(described_class::ERROR_VALUES).to be_an_instance_of(Set)
end
end
end

describe '.new' do
let(:path) { 'test/files/numeric-link.xlsx' }

Expand Down
2 changes: 1 addition & 1 deletion test/excelx/cell/test_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_formats_with_negative_numbers
end

def test_numbers_with_cell_errors
%w(#N/A #REF! #NAME? #DIV/0! #NULL! #VALUE! #NUM!).each do |error|
Excels::ERROR_VALUES.each do |error|
cell = Roo::Excelx::Cell::Number.new error, nil, ['General'], nil, nil, nil
assert_equal error, cell.value
assert_equal error, cell.formatted_value
Expand Down

0 comments on commit 3383085

Please sign in to comment.