saxlsx 1.5.0 → 1.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 597206ffbcc440bed3d0972489b4027464993b91
4
- data.tar.gz: 2286d59b75e1641f1ed47e927a25d612c7891111
3
+ metadata.gz: 912aea753226e55b3b97c74c094e36fff1a703b3
4
+ data.tar.gz: 71b3a09c85b6fbcb8dc5da74dfcb4134d4eb3ba6
5
5
  SHA512:
6
- metadata.gz: e5d5d8e6b1e6e29e2fbcc28b40bd9ce91a9d10d56b40fc15a56ca73a6a002eca850e875f977c2d8a9f01ed4df11affafae1762205aac35a613762085515ee3a1
7
- data.tar.gz: 9dffa50378a9f632982978496fdd1d959990e6c9836d280b7e7dff43980b4f8edbf43a1d5694690986b90b8c523d36b47388675234d640f7558e17cfed247894
6
+ metadata.gz: ee4a4b76abdf8d4d797a1704c892cd9359b2b2a646ac38267feeba182d7f349b7016c50788e0382ef9552cc767f2b3356ef5adbf462cc761fc44d24ad164b410
7
+ data.tar.gz: 1cd5883650144d961e7ff726af1900d5ca037f4c0a9d5efd2aeccdcf9312145ee108c21a6b35e3be8ccde8d942b2b578ed5e0be1c75fb077c8798c6ed947cbf6
@@ -14,8 +14,8 @@ module Saxlsx
14
14
  9 => :percentage, # 0%
15
15
  10 => :percentage, # 0.00%
16
16
  11 => :bignum, # 0.00E+00
17
- 12 => :unsupported, # # ?/?
18
- 13 => :unsupported, # # ??/??
17
+ 12 => :rational, # # ?/?
18
+ 13 => :rational, # # ??/??
19
19
  14 => :date, # mm-dd-yy
20
20
  15 => :date, # d-mmm-yy
21
21
  16 => :date, # d-mmm
@@ -42,6 +42,7 @@ module Saxlsx
42
42
 
43
43
  def initialize(workbook, &block)
44
44
  @base_date = workbook.base_date
45
+ @auto_format = workbook.auto_format
45
46
  @shared_strings = workbook.shared_strings
46
47
  @number_formats = workbook.number_formats
47
48
  @block = block
@@ -109,17 +110,20 @@ module Saxlsx
109
110
  date = @base_date + Rational((Float(text) * SECONDS_IN_DAY).round, SECONDS_IN_DAY)
110
111
  DateTime.new(date.year, date.month, date.day, date.hour, date.minute, date.second)
111
112
  when :fixnum
112
- Integer(text)
113
+ Integer(text, 10)
113
114
  when :float, :percentage
114
115
  Float(text)
116
+ when :rational
117
+ Rational(text)
115
118
  when :bignum
116
119
  Float(text) # raises ArgumentError if text is not a number
117
120
  BigDecimal(text) # doesn't raise ArgumentError
118
121
  else
119
122
  if @current_type == 'n'
120
123
  Float(text)
121
- elsif text =~ /\A-?\d+(\.\d+(?:e[+-]\d+)?)?\Z/i # Auto convert numbers
122
- $1 ? Float(text) : Integer(text)
124
+ elsif @auto_format && text =~ /\A-?\d+(\.\d+(?:e[+-]\d+)?)?\Z/i
125
+ # Auto convert numbers
126
+ $1 ? Float(text) : Integer(text, 10)
123
127
  else
124
128
  CGI.unescapeHTML(text)
125
129
  end
@@ -1,3 +1,3 @@
1
1
  module Saxlsx
2
- VERSION = '1.5.0'
2
+ VERSION = '1.6.0'
3
3
  end
@@ -4,18 +4,20 @@ module Saxlsx
4
4
  DATE_SYSTEM_1904 = DateTime.new(1904, 1, 1)
5
5
 
6
6
  attr_accessor :date1904
7
+ attr_reader :auto_format
7
8
 
8
- def self.open(filename)
9
+ def self.open(*args)
9
10
  begin
10
- workbook = self.new(filename)
11
+ workbook = self.new(*args)
11
12
  yield workbook
12
13
  ensure
13
14
  workbook.close
14
15
  end
15
16
  end
16
17
 
17
- def initialize(filename)
18
+ def initialize(filename, auto_format: true)
18
19
  @file_system = FileSystem.new filename
20
+ @auto_format = auto_format
19
21
  end
20
22
 
21
23
  def close
@@ -121,10 +121,12 @@ describe Sheet do
121
121
  end
122
122
  end
123
123
 
124
- context 'with number formats' do
124
+ context 'with number formats and auto format' do
125
125
  let(:filename) { "#{File.dirname(__FILE__)}/data/SpecNumberFormat.xlsx" }
126
126
 
127
127
  [ ["General", "Test"],
128
+ ["General", 123],
129
+ ["General", 123.5],
128
130
  ["Fixnum", 123],
129
131
  ["Currency", 123.0],
130
132
  ["Date", DateTime.new(1970, 1, 1)],
@@ -145,4 +147,31 @@ describe Sheet do
145
147
  end
146
148
  end
147
149
  end
150
+
151
+ context 'with number formats and without auto format' do
152
+ let(:filename) { "#{File.dirname(__FILE__)}/data/SpecNumberFormat.xlsx" }
153
+
154
+ [ ["General", "Test"],
155
+ ["General", "0123"],
156
+ ["General", "0123.50"],
157
+ ["Fixnum", 123],
158
+ ["Currency", 123.0],
159
+ ["Date", DateTime.new(1970, 1, 1)],
160
+ ["Time", DateTime.new(2015, 2, 13, 12, 40, 5)],
161
+ ["Percentage", 0.9999],
162
+ ["Fraction", 0.5],
163
+ ["Scientific", BigDecimal.new('3.4028236692093801E+38')],
164
+ ["Custom", 123.0],
165
+ ].each.with_index do |row, i|
166
+ name, value = row
167
+
168
+ it "should typecast #{name}" do
169
+ Workbook.open filename, auto_format: false do |w|
170
+ w.sheets[0].tap do |s|
171
+ expect(s.rows[i+1]).to eq([name, value, "Test"])
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
148
177
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgars Beigarts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2017-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip