rusk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,272 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
3
+
4
+ describe Rusk::Cell do
5
+ before do
6
+ @general_datas_content = Nokogiri::XML(File.read("#{dir}/general_datas_content.xml"))
7
+ @cells = []
8
+ @general_datas_content.xpath('.//table:table-row').each do |i|
9
+ @cells << i.xpath(".//table:table-cell|.//table:covered-table-cell")
10
+ end
11
+ end
12
+
13
+ shared_context "rusk::cell when boolean(true)" do
14
+ before do
15
+ @cell = Rusk::Cell.new(@cells[14][1])
16
+ end
17
+ end
18
+
19
+ shared_context "rusk::cell when boolean(false)" do
20
+ before do
21
+ @cell = Rusk::Cell.new(@cells[14][2])
22
+ end
23
+ end
24
+
25
+ shared_context "rusk::cell when currency" do
26
+ before do
27
+ @cell = Rusk::Cell.new(@cells[15][1])
28
+ end
29
+ end
30
+
31
+ shared_context "rusk::cell when string cell" do
32
+ before do
33
+ @cell = Rusk::Cell.new(@cells[0][1])
34
+ end
35
+ end
36
+
37
+ shared_context "rusk::cell when date cell" do
38
+ before do
39
+ @cell = Rusk::Cell.new(@cells[1][1])
40
+ end
41
+ end
42
+
43
+ shared_context "rusk::cell when enter date of time cell" do
44
+ before do
45
+ @cell = Rusk::Cell.new(@cells[13][1])
46
+ end
47
+ end
48
+
49
+ shared_context "rusk::cell when time cell" do
50
+ before do
51
+ @cell = Rusk::Cell.new(@cells[2][1])
52
+ end
53
+ end
54
+
55
+ shared_context "rusk::cell when float cell" do
56
+ before do
57
+ @cell = Rusk::Cell.new(@cells[3][1])
58
+ end
59
+ end
60
+
61
+ shared_context "rusk::cell when percentage cell" do
62
+ before do
63
+ @cell = Rusk::Cell.new(@cells[12][1])
64
+ end
65
+ end
66
+
67
+ describe "#value_type" do
68
+ context "when enter boolean" do
69
+ include_context "rusk::cell when boolean(true)"
70
+ it { @cell.value_type.should eq "boolean" }
71
+ end
72
+
73
+ context "when enter currency" do
74
+ include_context "rusk::cell when currency"
75
+ it { @cell.value_type.should eq "currency" }
76
+ end
77
+
78
+ context "when string cell" do
79
+ include_context "rusk::cell when string cell"
80
+ it { @cell.value_type.should eq "string" }
81
+ end
82
+
83
+ context "when date cell" do
84
+ include_context "rusk::cell when date cell"
85
+ it { @cell.value_type.should eq "date" }
86
+ end
87
+
88
+ context "when enter date of time cell" do
89
+ include_context "rusk::cell when enter date of time cell"
90
+ it { @cell.value_type.should eq "date" }
91
+ end
92
+
93
+ context "when time cell(not datetime)" do
94
+ include_context "rusk::cell when time cell"
95
+ it { @cell.value_type.should eq "time" }
96
+ end
97
+
98
+ context "when float cell" do
99
+ include_context "rusk::cell when float cell"
100
+ it { @cell.value_type.should eq "float" }
101
+ end
102
+
103
+ context "when percentage cell" do
104
+ include_context "rusk::cell when percentage cell"
105
+ it { @cell.value_type.should eq "percentage" }
106
+ end
107
+
108
+ end
109
+
110
+ describe "#value" do
111
+ context "when boolean cell(true)" do
112
+ include_context "rusk::cell when boolean(true)"
113
+ it { @cell.value.should be_true }
114
+ end
115
+
116
+ context "when boolean cell(false)" do
117
+ include_context "rusk::cell when boolean(false)"
118
+ it { @cell.value.should be_false }
119
+ end
120
+
121
+ context "when currency cell" do
122
+ include_context "rusk::cell when currency"
123
+ it { @cell.value.should eq 10.0 }
124
+ end
125
+
126
+ context "when string cell" do
127
+ include_context "rusk::cell when string cell"
128
+ it { @cell.value.should eq "mruby" }
129
+ end
130
+
131
+ context "when date cell" do
132
+ include_context "rusk::cell when date cell"
133
+ it { @cell.value.should eq Date.new(2012,4,29) }
134
+ end
135
+
136
+ context "when enter date of time cell" do
137
+ include_context "rusk::cell when enter date of time cell"
138
+ it { @cell.value.should eq DateTime.new(2012,5,26,18,17) }
139
+ end
140
+
141
+ context "when time cell(not datetime)" do
142
+ include_context "rusk::cell when time cell"
143
+ it { @cell.value.should eq "16:50" }
144
+ end
145
+
146
+ context "when float cell" do
147
+ include_context "rusk::cell when float cell"
148
+ it { @cell.value.should eq 7000.0 }
149
+ end
150
+
151
+ context "when percentage cell" do
152
+ include_context "rusk::cell when percentage cell"
153
+ it { @cell.value.should eq 0.1 }
154
+ end
155
+
156
+ end
157
+
158
+ describe "#to_s" do
159
+ context "when boolean cell(true)" do
160
+ include_context "rusk::cell when boolean(true)"
161
+ it { @cell.to_s.should eq 'TRUE' }
162
+ end
163
+
164
+ context "when boolean cell(false)" do
165
+ include_context "rusk::cell when boolean(false)"
166
+ it { @cell.to_s.should eq 'FALSE' }
167
+ end
168
+
169
+ context "when currency cell" do
170
+ include_context "rusk::cell when currency"
171
+ it { @cell.to_s.should eq '$10.00' }
172
+ end
173
+
174
+ context "when string cell" do
175
+ include_context "rusk::cell when string cell"
176
+ it { @cell.to_s.should eq "mruby" }
177
+ end
178
+
179
+ context "when date cell" do
180
+ include_context "rusk::cell when date cell"
181
+ it { @cell.to_s.should eq 'April 29, 2012' }
182
+ end
183
+
184
+ context "when enter date of time cell" do
185
+ include_context "rusk::cell when enter date of time cell"
186
+ it { @cell.to_s.should eq '2012/5/26 18:17' }
187
+ end
188
+
189
+ context "when time cell(not datetime)" do
190
+ include_context "rusk::cell when time cell"
191
+ it { @cell.to_s.should eq "16:50" }
192
+ end
193
+
194
+ context "when float cell" do
195
+ include_context "rusk::cell when float cell"
196
+ it { @cell.to_s.should eq '7000' }
197
+ end
198
+
199
+ context "when percentage cell" do
200
+ include_context "rusk::cell when percentage cell"
201
+ it { @cell.to_s.should eq '10%' }
202
+ end
203
+
204
+ end
205
+
206
+ describe "modify ods file" do
207
+ before do
208
+ @tmp_file = create_tmp
209
+ end
210
+
211
+ after do
212
+ remove_tmp
213
+ end
214
+
215
+ describe "#value=" do
216
+ context "'mruby' changed to 'cruby'(string cell changed to string)" do
217
+ before do
218
+ Rusk::Book.open(@tmp_file) do |book|
219
+ sheet = book[0]
220
+ sheet[0,1].value = "cruby"
221
+ book.save
222
+ end
223
+
224
+ Rusk::Book.open(@tmp_file) do |book|
225
+ sheet = book[0]
226
+ @cell = sheet[0,1]
227
+ end
228
+ end
229
+
230
+ it { @cell.value.should eq "cruby" }
231
+ end
232
+
233
+ context "string cell changed to date" do
234
+ before do
235
+ Rusk::Book.open(@tmp_file) do |book|
236
+ sheet = book[0]
237
+ sheet[0,1].value = Date.new(2012,5,7)
238
+ book.save
239
+ end
240
+
241
+ Rusk::Book.open(@tmp_file) do |book|
242
+ sheet = book[0]
243
+ @cell = sheet[0,1]
244
+ end
245
+ end
246
+
247
+ it { @cell.value.should eq Date.new(2012,5,07) }
248
+ it { @cell.value_type.should eq 'date' }
249
+ end
250
+
251
+ context "string cell changed to float" do
252
+ before do
253
+ Rusk::Book.open(@tmp_file) do |book|
254
+ sheet = book[0]
255
+ sheet[0,1].value = 500.1
256
+ book.save
257
+ end
258
+
259
+ Rusk::Book.open(@tmp_file) do |book|
260
+ sheet = book[0]
261
+ @cell = sheet[0,1]
262
+ end
263
+ end
264
+
265
+ it { @cell.value.should eq 500.1 }
266
+ it { @cell.value_type.should eq 'float' }
267
+ end
268
+
269
+ end
270
+ end
271
+
272
+ end
@@ -0,0 +1,217 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
3
+ <office:scripts/>
4
+ <office:font-face-decls>
5
+ <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/>
6
+ <style:font-face style:name="Arial Unicode MS" svg:font-family="'Arial Unicode MS'" style:font-family-generic="system" style:font-pitch="variable"/>
7
+ <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-family-generic="system" style:font-pitch="variable"/>
8
+ <style:font-face style:name="ヒラギノ角ゴ ProN W3" svg:font-family="'ヒラギノ角ゴ ProN W3'" style:font-family-generic="system" style:font-pitch="variable"/>
9
+ </office:font-face-decls>
10
+ <office:automatic-styles>
11
+ <style:style style:name="co1" style:family="table-column">
12
+ <style:table-column-properties fo:break-before="auto" style:column-width="2.267cm"/>
13
+ </style:style>
14
+ <style:style style:name="ro2" style:family="table-row">
15
+ <style:table-row-properties style:row-height="0.448cm" fo:break-before="auto" style:use-optimal-row-height="true"/>
16
+ </style:style>
17
+ <style:style style:name="ta1" style:family="table" style:master-page-name="Default">
18
+ <style:table-properties table:display="true" style:writing-mode="lr-tb"/>
19
+ </style:style>
20
+ <number:percentage-style style:name="N10">
21
+ <number:number number:decimal-places="0" number:min-integer-digits="1"/>
22
+ <number:text>%</number:text>
23
+ </number:percentage-style>
24
+ <number:date-style style:name="N51">
25
+ <number:year number:style="long"/>
26
+ <number:text>/</number:text>
27
+ <number:month/>
28
+ <number:text>/</number:text>
29
+ <number:day/>
30
+ <number:text> </number:text>
31
+ <number:hours/>
32
+ <number:text>:</number:text>
33
+ <number:minutes number:style="long"/>
34
+ </number:date-style>
35
+ <number:boolean-style style:name="N99">
36
+ <number:boolean/>
37
+ </number:boolean-style>
38
+ <number:time-style style:name="N5040" number:language="en" number:country="US">
39
+ <number:hours number:style="long"/>
40
+ <number:text>:</number:text>
41
+ <number:minutes number:style="long"/>
42
+ </number:time-style>
43
+ <number:date-style style:name="N5076" number:language="en" number:country="US" number:automatic-order="true">
44
+ <number:month number:style="long" number:textual="true"/>
45
+ <number:text> </number:text>
46
+ <number:day/>
47
+ <number:text>, </number:text>
48
+ <number:year number:style="long"/>
49
+ </number:date-style>
50
+ <number:currency-style style:name="N5104P0" style:volatile="true" number:language="en" number:country="US">
51
+ <number:currency-symbol number:language="en" number:country="US">$</number:currency-symbol>
52
+ <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
53
+ </number:currency-style>
54
+ <number:currency-style style:name="N5104" number:language="en" number:country="US">
55
+ <style:text-properties fo:color="#ff0000"/>
56
+ <number:text>-</number:text>
57
+ <number:currency-symbol number:language="en" number:country="US">$</number:currency-symbol>
58
+ <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
59
+ <style:map style:condition="value()&gt;=0" style:apply-style-name="N5104P0"/>
60
+ </number:currency-style>
61
+ <style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N5076"/>
62
+ <style:style style:name="ce2" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N5040"/>
63
+ <style:style style:name="ce3" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N10"/>
64
+ <style:style style:name="ce4" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N51"/>
65
+ <style:style style:name="ce5" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N99"/>
66
+ <style:style style:name="ce6" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N5104"/>
67
+ </office:automatic-styles>
68
+ <office:body>
69
+ <office:spreadsheet>
70
+ <table:table table:name="Sheet1" table:style-name="ta1">
71
+ <table:table-column table:style-name="co1" table:number-columns-repeated="3" table:default-cell-style-name="Default"/>
72
+ <table:table-row table:style-name="ro2">
73
+ <table:table-cell office:value-type="string">
74
+ <text:p>string</text:p>
75
+ </table:table-cell>
76
+ <table:table-cell office:value-type="string">
77
+ <text:p>mruby</text:p>
78
+ </table:table-cell>
79
+ <table:table-cell/>
80
+ </table:table-row>
81
+ <table:table-row table:style-name="ro2">
82
+ <table:table-cell office:value-type="string">
83
+ <text:p>date</text:p>
84
+ </table:table-cell>
85
+ <table:table-cell table:style-name="ce1" office:value-type="date" office:date-value="2012-04-29">
86
+ <text:p>April 29, 2012</text:p>
87
+ </table:table-cell>
88
+ <table:table-cell/>
89
+ </table:table-row>
90
+ <table:table-row table:style-name="ro2">
91
+ <table:table-cell office:value-type="string">
92
+ <text:p>time</text:p>
93
+ </table:table-cell>
94
+ <table:table-cell table:style-name="ce2" office:value-type="time" office:time-value="PT16H50M00S">
95
+ <text:p>16:50</text:p>
96
+ </table:table-cell>
97
+ <table:table-cell/>
98
+ </table:table-row>
99
+ <table:table-row table:style-name="ro2">
100
+ <table:table-cell office:value-type="string">
101
+ <text:p>float</text:p>
102
+ </table:table-cell>
103
+ <table:table-cell office:value-type="float" office:value="7000">
104
+ <text:p>7000</text:p>
105
+ </table:table-cell>
106
+ <table:table-cell/>
107
+ </table:table-row>
108
+ <table:table-row table:style-name="ro2">
109
+ <table:table-cell office:value-type="string" table:number-columns-spanned="2" table:number-rows-spanned="1">
110
+ <text:p>merged_cell</text:p>
111
+ </table:table-cell>
112
+ <table:covered-table-cell/>
113
+ <table:table-cell office:value-type="string">
114
+ <text:p>after merged column</text:p>
115
+ </table:table-cell>
116
+ </table:table-row>
117
+ <table:table-row table:style-name="ro2">
118
+ <table:table-cell office:value-type="string" table:number-columns-spanned="1" table:number-rows-spanned="2">
119
+ <text:p>merged_row cell</text:p>
120
+ </table:table-cell>
121
+ <table:table-cell office:value-type="string">
122
+ <text:p>merged first row cell</text:p>
123
+ </table:table-cell>
124
+ <table:table-cell/>
125
+ </table:table-row>
126
+ <table:table-row table:style-name="ro2">
127
+ <table:covered-table-cell/>
128
+ <table:table-cell office:value-type="string">
129
+ <text:p>merged second row cell</text:p>
130
+ </table:table-cell>
131
+ <table:table-cell/>
132
+ </table:table-row>
133
+ <table:table-row table:style-name="ro2">
134
+ <table:table-cell office:value-type="string">
135
+ <text:p>after merged row cell</text:p>
136
+ </table:table-cell>
137
+ <table:table-cell table:number-columns-repeated="2"/>
138
+ </table:table-row>
139
+ <table:table-row table:style-name="ro2">
140
+ <table:table-cell table:number-columns-repeated="3"/>
141
+ </table:table-row>
142
+ <table:table-row table:style-name="ro2">
143
+ <table:table-cell office:value-type="string">
144
+ <text:p>after blank row</text:p>
145
+ </table:table-cell>
146
+ <table:table-cell table:number-columns-repeated="2"/>
147
+ </table:table-row>
148
+ <table:table-row table:style-name="ro2">
149
+ <table:table-cell/>
150
+ <table:table-cell office:value-type="string">
151
+ <text:p>after blank column</text:p>
152
+ </table:table-cell>
153
+ <table:table-cell/>
154
+ </table:table-row>
155
+ <table:table-row table:style-name="ro2">
156
+ <table:table-cell office:value-type="string" table:number-columns-spanned="2" table:number-rows-spanned="1">
157
+ <text:p>hide the cell next to</text:p>
158
+ </table:table-cell>
159
+ <table:covered-table-cell office:value-type="string">
160
+ <text:p>hidden cell</text:p>
161
+ </table:covered-table-cell>
162
+ <table:table-cell/>
163
+ </table:table-row>
164
+ <table:table-row table:style-name="ro2">
165
+ <table:table-cell office:value-type="string">
166
+ <text:p>percentage</text:p>
167
+ </table:table-cell>
168
+ <table:table-cell table:style-name="ce3" office:value-type="percentage" office:value="0.1">
169
+ <text:p>10%</text:p>
170
+ </table:table-cell>
171
+ <table:table-cell/>
172
+ </table:table-row>
173
+ <table:table-row table:style-name="ro2">
174
+ <table:table-cell office:value-type="string">
175
+ <text:p>enter date of time</text:p>
176
+ </table:table-cell>
177
+ <table:table-cell table:style-name="ce4" office:value-type="date" office:date-value="2012-05-26T18:17:00">
178
+ <text:p>2012/5/26 18:17</text:p>
179
+ </table:table-cell>
180
+ <table:table-cell/>
181
+ </table:table-row>
182
+ <table:table-row table:style-name="ro2">
183
+ <table:table-cell office:value-type="string">
184
+ <text:p>boolean</text:p>
185
+ </table:table-cell>
186
+ <table:table-cell table:style-name="ce5" office:value-type="boolean" office:boolean-value="true">
187
+ <text:p>TRUE</text:p>
188
+ </table:table-cell>
189
+ <table:table-cell table:style-name="ce5" office:value-type="boolean" office:boolean-value="false">
190
+ <text:p>FALSE</text:p>
191
+ </table:table-cell>
192
+ </table:table-row>
193
+ <table:table-row table:style-name="ro2">
194
+ <table:table-cell office:value-type="string">
195
+ <text:p>currency</text:p>
196
+ </table:table-cell>
197
+ <table:table-cell table:style-name="ce6" office:value-type="currency" office:currency="USD" office:value="10">
198
+ <text:p>$10.00</text:p>
199
+ </table:table-cell>
200
+ <table:table-cell/>
201
+ </table:table-row>
202
+ </table:table>
203
+ <table:table table:name="Sheet2" table:style-name="ta1">
204
+ <table:table-column table:style-name="co1" table:default-cell-style-name="Default"/>
205
+ <table:table-row table:style-name="ro2">
206
+ <table:table-cell/>
207
+ </table:table-row>
208
+ </table:table>
209
+ <table:table table:name="Sheet3" table:style-name="ta1">
210
+ <table:table-column table:style-name="co1" table:default-cell-style-name="Default"/>
211
+ <table:table-row table:style-name="ro2">
212
+ <table:table-cell/>
213
+ </table:table-row>
214
+ </table:table>
215
+ </office:spreadsheet>
216
+ </office:body>
217
+ </office:document-content>