Skip to content

Commit 67f0f22

Browse files
[ creek #70 ] fixed.
1 parent dcae13e commit 67f0f22

6 files changed

Lines changed: 42 additions & 3 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

lib/creek/styles/converter.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ def self.call(value, type, style, options = {})
5454
# detected earlier and cast here by its standardized symbol
5555
##
5656

57-
when :string, :unsupported
57+
when :string
5858
value
59+
when :unsupported
60+
convert_unknown(value)
5961
when :fixnum
6062
value.to_i
6163
when :float, :percentage
@@ -69,7 +71,23 @@ def self.call(value, type, style, options = {})
6971

7072
## Nothing matched
7173
else
72-
value
74+
convert_unknown(value)
75+
end
76+
end
77+
78+
def self.convert_unknown(value)
79+
begin
80+
if value.nil? or value.empty?
81+
return value
82+
elsif value.to_i.to_s == value.to_s
83+
return value.to_i
84+
elsif value.to_f.to_s == value.to_s
85+
return value.to_f
86+
else
87+
return value
88+
end
89+
rescue
90+
return value
7391
end
7492
end
7593

lib/creek/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Creek
2-
VERSION = "2.4"
2+
VERSION = "2.4.1"
33
end

spec/.DS_Store

6 KB
Binary file not shown.

spec/fixtures/large_numbers.xlsx

8.52 KB
Binary file not shown.

spec/test_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@
5454
end
5555
end
5656

57+
describe 'Creek parsing a file with large numbrts.' do
58+
before(:all) do
59+
@creek = Creek::Book.new 'spec/fixtures/large_numbers.xlsx'
60+
@expected_simple_rows = [{"A"=>"7.83294732E8", "B"=>"783294732", "C"=>783294732.0}]
61+
end
62+
63+
after(:all) do
64+
@creek.close
65+
end
66+
67+
it 'Parse simple rows successfully.' do
68+
rows = Array.new
69+
row_count = 0
70+
@creek.sheets[0].simple_rows.each do |row|
71+
rows << row
72+
row_count += 1
73+
end
74+
expect(rows[0]).to eq(@expected_simple_rows[0])
75+
end
76+
end
77+
5778
describe 'Creek parsing a sample XLSX file' do
5879
before(:all) do
5980
@creek = Creek::Book.new 'spec/fixtures/sample.xlsx'

0 commit comments

Comments
 (0)