Skip to content

Commit

Permalink
Improve type casting
Browse files Browse the repository at this point in the history
  • Loading branch information
ebeigarts committed Mar 25, 2015
1 parent 5cc3fec commit c662465
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/saxlsx/rows_collection_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ def value_of(text)
@shared_strings[text.to_i]
when 'b'
BooleanParser.parse text
when 'n'
text.to_f
else
case @current_number_format
when :date
Expand All @@ -119,8 +117,9 @@ def value_of(text)
when :percentage
text.to_f / 100
else
# Auto convert numbers
if text =~ /\A-?\d+(\.\d+(?:e[+-]\d+)?)?\Z/i
if @current_type == 'n'
text.to_f
elsif text =~ /\A-?\d+(\.\d+(?:e[+-]\d+)?)?\Z/i # Auto convert numbers
$1 ? text.to_f : text.to_i
else
CGI.unescapeHTML(text)
Expand All @@ -141,6 +140,7 @@ def detect_format_type(index)
#
# http://stackoverflow.com/questions/4948998/determining-if-an-xlsx-cell-is-date-formatted-for-excel-2007-spreadsheets
def detect_custom_format_type(code)
code = code.gsub(/\[[^\]]+\]/, '') # Strip meta - [...]
if code =~ /0/
:float
elsif code =~ /[ymdhis]/i
Expand Down

0 comments on commit c662465

Please sign in to comment.