rspreadsheet 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/rspreadsheet/cell.rb +19 -9
- data/lib/rspreadsheet/row.rb +8 -1
- data/lib/rspreadsheet/version.rb +1 -1
- data/spec/cell_spec.rb +14 -0
- 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: 5e68b11b80d618d17de31bb79ff8723d7367dbbc
|
4
|
+
data.tar.gz: 5cf05fdad441db2cea08b21784ce55cac716b149
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c438393ef32daba2c6deb4d4d4b251125adc6322ad39297e1f6a4c9d08a7814ff76e5d8f40679e470ffb76fc295048e9da44b590f0561b93dce984617bbf137
|
7
|
+
data.tar.gz: 0a125394984f40ae1aa8fe2db8c142f3a04e921b580714019ee4d29075f549d784c2773cd688b4482600a2eec83ef6ec406b2903d83f83a7c08ec79af470cb8a
|
data/.gitignore
CHANGED
data/lib/rspreadsheet/cell.rb
CHANGED
@@ -122,33 +122,39 @@ class Cell < XMLTiedItem
|
|
122
122
|
detach_if_needed
|
123
123
|
if self.mode == :regular
|
124
124
|
gt = guess_cell_type(avalue)
|
125
|
+
# raise 'here'+gt.to_s if avalue == 666.66
|
125
126
|
case
|
126
127
|
when gt == nil then raise 'This value type is not storable to cell'
|
127
128
|
when gt == Float then
|
128
|
-
remove_all_value_attributes_and_content
|
129
|
+
remove_all_value_attributes_and_content
|
129
130
|
set_type_attribute('float')
|
130
131
|
Tools.set_ns_attribute(xmlnode,'office','value', avalue.to_s)
|
131
132
|
xmlnode << Tools.prepare_ns_node('text','p', avalue.to_f.to_s)
|
132
133
|
when gt == String then
|
133
|
-
remove_all_value_attributes_and_content
|
134
|
+
remove_all_value_attributes_and_content
|
134
135
|
set_type_attribute('string')
|
135
136
|
xmlnode << Tools.prepare_ns_node('text','p', avalue.to_s)
|
136
137
|
when gt == :datetime then
|
137
|
-
remove_all_value_attributes_and_content
|
138
|
+
remove_all_value_attributes_and_content
|
138
139
|
set_type_attribute('date')
|
139
140
|
avalue = avalue.strftime(InternalDateTimeFormat)
|
140
141
|
Tools.set_ns_attribute(xmlnode,'office','date-value', avalue)
|
141
142
|
xmlnode << Tools.prepare_ns_node('text','p', avalue)
|
142
143
|
when gt == :time then
|
143
|
-
remove_all_value_attributes_and_content
|
144
|
+
remove_all_value_attributes_and_content
|
144
145
|
set_type_attribute('time')
|
145
146
|
Tools.set_ns_attribute(xmlnode,'office','time-value', avalue.strftime(InternalTimeFormat))
|
146
147
|
xmlnode << Tools.prepare_ns_node('text','p', avalue.strftime('%H:%M'))
|
147
148
|
when gt == :percentage then
|
148
|
-
remove_all_value_attributes_and_content
|
149
|
+
remove_all_value_attributes_and_content
|
149
150
|
set_type_attribute('percentage')
|
150
151
|
Tools.set_ns_attribute(xmlnode,'office','value', '%0.2d%' % avalue.to_f)
|
151
152
|
xmlnode << Tools.prepare_ns_node('text','p', (avalue.to_f*100).round.to_s+'%')
|
153
|
+
when gt == :currency then
|
154
|
+
remove_all_value_attributes_and_content
|
155
|
+
set_type_attribute('currency')
|
156
|
+
Tools.set_ns_attribute(xmlnode,'office','value', '%f' % avalue.to_d)
|
157
|
+
xmlnode << Tools.prepare_ns_node('text','p', avalue.to_d.to_s+' '+self.format.currency)
|
152
158
|
end
|
153
159
|
else
|
154
160
|
raise "Unknown cell mode #{self.mode}"
|
@@ -158,6 +164,7 @@ class Cell < XMLTiedItem
|
|
158
164
|
Tools.set_ns_attribute(xmlnode,'office','value-type',typestring)
|
159
165
|
Tools.set_ns_attribute(xmlnode,'calcext','value-type',typestring)
|
160
166
|
end
|
167
|
+
## TODO: using this is NOT in line with the general intent of forward compatibility
|
161
168
|
def remove_all_value_attributes_and_content(node=xmlnode)
|
162
169
|
if att = Tools.get_ns_attribute(node, 'office','value') then att.remove! end
|
163
170
|
if att = Tools.get_ns_attribute(node, 'office','date-value') then att.remove! end
|
@@ -197,7 +204,7 @@ class Cell < XMLTiedItem
|
|
197
204
|
end
|
198
205
|
result = valueguess
|
199
206
|
|
200
|
-
if valueguess.nil?
|
207
|
+
if valueguess.nil? # valueguess is most important if not succesfull then try guessing by type from node xml
|
201
208
|
typ = xmlnode.nil? ? 'N/A' : xmlnode.attributes['value-type']
|
202
209
|
typeguess = case typ
|
203
210
|
when nil then nil
|
@@ -229,7 +236,7 @@ class Cell < XMLTiedItem
|
|
229
236
|
else # without value we just beleive typeguess
|
230
237
|
typeguess
|
231
238
|
end
|
232
|
-
else
|
239
|
+
else # it not have a typeguess
|
233
240
|
if (avalue.nil?) # if nil then nil
|
234
241
|
NilClass
|
235
242
|
elsif (String(avalue) rescue false) # convertible to String
|
@@ -238,8 +245,11 @@ class Cell < XMLTiedItem
|
|
238
245
|
nil
|
239
246
|
end
|
240
247
|
end
|
241
|
-
elsif valueguess == Float
|
242
|
-
|
248
|
+
elsif valueguess == Float
|
249
|
+
case xmlnode.andand.attributes['value-type']
|
250
|
+
when 'percentage' then result = :percentage
|
251
|
+
when 'currency' then result = :currency
|
252
|
+
end
|
243
253
|
end
|
244
254
|
result
|
245
255
|
end
|
data/lib/rspreadsheet/row.rb
CHANGED
@@ -96,6 +96,13 @@ class Row < XMLTiedItem
|
|
96
96
|
parent.add_row_above(rowi)
|
97
97
|
end
|
98
98
|
|
99
|
+
def next_row; relative(+1) end
|
100
|
+
alias :next :next_row
|
101
|
+
|
102
|
+
def relative(rowi_offset)
|
103
|
+
worksheet.row(self.rowi+rowi_offset)
|
104
|
+
end
|
105
|
+
|
99
106
|
# @!group Private methods, which should not be called directly
|
100
107
|
# @private
|
101
108
|
# shifts internal represetation of row by diff. This should not be called directly
|
@@ -114,4 +121,4 @@ class Row < XMLTiedItem
|
|
114
121
|
|
115
122
|
end
|
116
123
|
|
117
|
-
end
|
124
|
+
end
|
data/lib/rspreadsheet/version.rb
CHANGED
data/spec/cell_spec.rb
CHANGED
@@ -371,6 +371,20 @@ describe Rspreadsheet::Cell do
|
|
371
371
|
@czkcell = @sheet2.cell('B23')
|
372
372
|
@czkcell.value.should == 344.to_d
|
373
373
|
@czkcell.format.currency.should == 'CZK'
|
374
|
+
|
375
|
+
@czkcell.value = 200.to_d
|
376
|
+
@czkcell.value.should == 200.to_d
|
377
|
+
@czkcell.format.currency.should == 'CZK'
|
378
|
+
end
|
379
|
+
it 'preserves currency format when float is assingned to it' do
|
380
|
+
@cell = @sheet2.cell('B23')
|
381
|
+
@cell.type.should eq :currency
|
382
|
+
@cell.format.currency.should == 'CZK'
|
383
|
+
|
384
|
+
@cell.value = 666.66.to_d
|
385
|
+
@cell.value.should == 666.66.to_d
|
386
|
+
@cell.type.should eq :currency
|
387
|
+
@cell.format.currency.should == 'CZK'
|
374
388
|
end
|
375
389
|
it 'is possible to manipulate borders of cells' do
|
376
390
|
@cell = @sheet1.cell(1,1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspreadsheet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub A.Těšínský
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libxml-ruby
|