rspreadsheet 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/spec/cell_spec.rb CHANGED
@@ -4,6 +4,7 @@ describe Rspreadsheet::Cell do
4
4
  before do
5
5
  book1 = Rspreadsheet.new
6
6
  @sheet1 = book1.create_worksheet
7
+ @c = @sheet1.cells(1,1)
7
8
  book2 = Rspreadsheet.new($test_filename)
8
9
  @sheet2 = book2.worksheets[1]
9
10
  end
@@ -12,7 +13,6 @@ describe Rspreadsheet::Cell do
12
13
  @cell.rowi.should == 1
13
14
  @cell.coli.should == 3
14
15
  @cell.coordinates.should == [1,3]
15
-
16
16
  @cell = @sheet2.cells(7,2)
17
17
  @cell.rowi.should == 7
18
18
  @cell.coli.should == 2
@@ -31,9 +31,16 @@ describe Rspreadsheet::Cell do
31
31
  @cell.value.should == 'zadruhe'
32
32
  @sheet1.B2 = 'zatreti'
33
33
  @cell.value.should == 'zatreti'
34
+ @sheet1.rows(2).cells(2).value = 'zactvrte'
35
+ @cell.value.should == 'zactvrte'
36
+ @sheet1.rows(2)[2] = 'zapate'
37
+ @cell.value.should == 'zapate'
34
38
  end
35
39
  it 'can include links' do
36
40
  @sheet2.A12.should == '[http://example.org/]'
41
+ @sheet2.cells(12,2).valuexmlfindall('.//text:a').size.should eq 0
42
+ @sheet2.cells(12,1).valuexmlfindall('.//text:a').size.should eq 1
43
+ @sheet2.cells(12,1).valuexmlfindfirst('.//text:a').attributes['href'].should eq 'http://example.org/'
37
44
  end
38
45
  it 'contains good row and col coordinates even after table:number-columns-repeated cells' do
39
46
  @cell = @sheet2.cells(13,5)
@@ -41,6 +48,11 @@ describe Rspreadsheet::Cell do
41
48
  @cell.rowi.should == 13
42
49
  @cell.coli.should == 5
43
50
  end
51
+ it 'reports good range of coordinates for repeated cells' do
52
+ @cell = @sheet2.cells(13,2)
53
+ @cell.range.should == (1..4)
54
+ @cell.mode.should == :repeated
55
+ end
44
56
  it 'does not accept negative and zero coordinates' do
45
57
  @sheet2.cells(0,5).should be(nil)
46
58
  @sheet2.cells(2,-5).should be(nil)
@@ -69,20 +81,185 @@ describe Rspreadsheet::Cell do
69
81
  @sheet2.cells(13,3).should_not == 'cokoli'
70
82
  @sheet2.cells(13,4).should_not == 'cokoli'
71
83
  end
72
- it 'returns type for the cell' do
73
- book = Rspreadsheet.new($test_filename)
74
- s = book.worksheets[1]
75
- s.cells(1,2).type.should === :string
76
- s.cells(2,2).type.should === :date
77
- s.cells(3,1).type.should === :float
78
- s.cells(3,2).type.should === :percentage
79
- s.cells(4,2).type.should === :string
80
- s.cells(200,200).type.should === :unassigned
84
+ it 'returns correct type for the cell' do
85
+ @sheet2.cells(1,2).type.should eq :string
86
+ @sheet2.cells(2,2).type.should eq :date
87
+ @sheet2.cells(3,1).type.should eq :float
88
+ @sheet2.cells(3,2).type.should eq :percentage
89
+ @sheet2.cells(4,2).type.should eq :string
90
+ @sheet2.cells(200,200).type.should eq :unassigned
91
+ end
92
+ it 'returns value of correct type' do
93
+ @sheet2[1,2].should be_kind_of(String)
94
+ @sheet2[2,2].should be_kind_of(Date)
95
+ @sheet2[3,1].should be_kind_of(Float)
96
+ @sheet2[3,2].should be_kind_of(Float)
97
+ @sheet2.cells(3,2).type.should eq :percentage
98
+ @sheet2.cells(3,2).guess_cell_type.should eq :percentage
99
+ @sheet2.cells(3,2).guess_cell_type(1).should eq :percentage
100
+ @sheet2[3,2]=0.1
101
+ @sheet2.cells(3,2).type.should eq :percentage
102
+ @sheet2[4,2].should be_kind_of(String)
81
103
  end
104
+ it 'is the same object no matter how you access it' do
105
+ @cell1 = @sheet2.cells(5,5)
106
+ @cell2 = @sheet2.rows(5).cells(5)
107
+ @cell1.should equal(@cell2)
108
+ end
109
+ it 'splits correctly cells if written in the middle of repeated group' do
110
+ @cell = @sheet2.cells(4,6)
111
+ @cell.range.should == (4..7)
112
+ @cell.value.should == 7
113
+
114
+ @cell.value = 'nebesa'
115
+ @cell.range.should == (6..6)
116
+ @cell.value.should == 'nebesa'
117
+
118
+ @cellA = @sheet2.cells(4,5)
119
+ @cellA.range.should == (4..5)
120
+ @cellA.value.should == 7
121
+
122
+ @cellB = @sheet2.cells(4,7)
123
+ @cellB.range.should == (7..7)
124
+ @cellB.value.should == 7
125
+ end
126
+ it 'inserts correctly cell in the middle of repeated group' do
127
+ @cell = @sheet2.cells(4,6)
128
+ @cell.range.should == (4..7)
129
+ @cell.value.should == 7
130
+ @cell.coli.should == 6
131
+
132
+ @sheet2.insert_cell_before(4,6)
133
+ @cell.coli.should == 7
134
+
135
+ @cellA = @sheet2.cells(4,5)
136
+ @cellA.range.should == (4..5)
137
+ @cellA.value.should == 7
138
+
139
+ @cellB = @sheet2.cells(4,7)
140
+ @cellB.range.should == (7..8)
141
+ @cellB.value.should == 7
142
+
143
+ @cell = @sheet2.cells(16,4)
144
+ @cell.range.should == (1..7)
145
+ @cell.value.should == ""
146
+
147
+ @sheet2.rows(15).range.should == (14..18)
148
+ @sheet2.rows(16).range.should == (14..18)
149
+ @sheet2.rows(17).range.should == (14..18)
150
+ @sheet2.insert_cell_before(16,3)
151
+ @sheet2.cells(16,3).value = 'baf'
152
+ @sheet2.cells(17,3).value.should_not == 'baf'
153
+ @sheet2.rows(15).range.should == (14..15)
154
+ @sheet2.rows(16).range.should == (16..16)
155
+ @sheet2.rows(17).range.should == (17..18)
156
+
157
+ @cellA = @sheet2.cells(16,1)
158
+ @cellA.range.should == (1..2)
159
+ @cellA.value.should == ""
160
+
161
+ @cellB = @sheet2.cells(16,5)
162
+ @cellB.range.should == (4..8)
163
+ @cellB.value.should == ""
82
164
 
165
+ end
166
+ it 'inserted has correct class' do # based on real error
167
+ @sheet2.insert_cell_before(1,1)
168
+ @sheet2.rows(1).cells(1).should be_kind_of(Rspreadsheet::Cell)
169
+ end
170
+ it 'can have different formats' do
171
+ @cell = @sheet2.cells(6,3)
172
+ @cell.format.bold.should == true
173
+ @cell = @sheet2.cells(6,4)
174
+ @cell.format.bold.should == false
175
+ @cell.format.italic.should == true
176
+ @cell = @sheet2.cells(6,5)
177
+ @cell.format.italic.should == false
178
+ @cell.format.color.should == '#ff3333'
179
+ @cell = @sheet2.cells(6,6)
180
+ @cell.format.color.should_not == '#ff3333'
181
+ @cell.format.background_color.should == '#6666ff'
182
+ @cell = @sheet2.cells(6,7)
183
+ @cell.format.font_size.should == '7pt'
184
+
185
+ # after fresh create
186
+ @cell.xmlnode.attributes['style-name'].should_not be_nil
187
+ end
188
+ it 'can set formats of the cells' do
189
+ skip 'not implemented yet'; pending
190
+ =begin
191
+ @cell = @sheet2.cells(1,1)
192
+ # bold
193
+ @cell.format.bold.should be_falsey
194
+ @cell.format.bold = true
195
+ @cell.format.bold.should be_truthy
196
+ # italic
197
+ @cell.format.italic.should be_falsey
198
+ @cell.format.italic = true
199
+ @cell.format.italic.should be_truthy
200
+ # color
201
+ @cell.format.color.should be_nil
202
+ @cell.format.color = '#AABBCC'
203
+ @cell.format.color.should eq '#AABBCC'
204
+ # background_color
205
+ @cell.format.background_color.should be_nil
206
+ @cell.format.background_color = '#AABBCC'
207
+ @cell.format.background_color.should eq '#AABBCC'
208
+ # font_size
209
+ @cell.format.font_size.should be_nil
210
+ @cell.format.font_size = '11pt'
211
+ @cell.format.font_size.should eq '11pt'
212
+ =end
213
+ end
214
+ it 'method cells without arguments returns array of cells' do
215
+ @a = @sheet2.rows(1).cells
216
+ @a.should be_kind_of(Array)
217
+ @a.each { |item| item.should be_kind_of(Rspreadsheet::Cell)}
218
+
219
+ end
220
+ it 'changes coordinates when row inserted above' do
221
+ @sheet1.cells(2,2).detach
222
+ @cell = @sheet1.cells(2,2)
223
+ @cell.rowi.should == 2
224
+ @sheet1.insert_row_above(1)
225
+ @cell.rowi.should == 3
226
+ end
227
+ it 'switches to invalid_reference cell when deleted' do
228
+ @sheet1[2,5] = 'nejaka data'
229
+ @cell = @sheet1.cells(2,2)
230
+ @cell.value = 'data'
231
+ @cell.invalid_reference?.should be false
232
+ @cell.delete
233
+ @cell.invalid_reference?.should be true
234
+ expect { @cell.rowi }.to raise_error
235
+ expect { @cell.address }.to raise_error
236
+
237
+ @sheet1.cells(2,2).type.should == :string
238
+ @sheet1.cells(3,2).type.should == :unassigned
239
+ end
240
+ it 'switches to invalid_reference cell when its row is deleted' do
241
+ @cell = @sheet1.cells(6,2)
242
+ @cell.value = 'data'
243
+ @cell.rowi.should == 6
244
+ @sheet1.rows(6).delete
245
+ expect { @cell.rowi }.to raise_error
246
+ @cell.invalid_reference?.should be true
247
+ end
248
+ it 'has inspect method returning something good' do
249
+ @cell = @sheet1.cells(6,2)
250
+ @cell.value = 'abcde'
251
+ expect(@cell.inspect).to include('abcde','::Cell','6','2','row')
252
+ end
253
+ it 'stores date correctly' do
254
+ @c.value= Date.parse('2014-01-02')
255
+ @c.value.year.should eq 2014
256
+ @c.value.month.should eq 1
257
+ @c.value.day.should eq 2
258
+ end
83
259
  end
84
260
 
85
261
 
86
262
 
87
263
 
88
264
 
265
+
data/spec/row_spec.rb CHANGED
@@ -13,7 +13,10 @@ describe Rspreadsheet::Row do
13
13
  end
14
14
  it 'can be detached and changes to unrepeated if done' do
15
15
  @row = @sheet1.rows(5)
16
+ @row.xmlnode.andand.name.should_not == 'table-row'
17
+
16
18
  @row2 = @row.detach
19
+ @row2.xmlnode.name.should == 'table-row'
17
20
  @row2.is_repeated?.should == false
18
21
  end
19
22
  it 'is the synchronized object, now matter how you access it' do
@@ -112,12 +115,6 @@ describe Rspreadsheet::Row do
112
115
  s[1,2].should === 'text'
113
116
  s[2,2].should === Date.new(2014,1,1)
114
117
  end
115
- # it 'normalizes to itself if single line' do
116
- # @sheet1.rows(5).detach
117
- # @sheet1.rows(5).cells(4).value='test'
118
- # @sheet1.rows(5).normalize
119
- # @sheet1.rows(5).cells(4).value.should == 'test'
120
- # end
121
118
  it 'cell manipulation does not contain attributes without namespace nor doubled attributes' do # inspired by a real bug regarding namespaces manipulation
122
119
  @sheet2.rows(1).xmlnode.attributes.each { |attr| attr.ns.should_not be_nil}
123
120
  @sheet2.rows(1).cells(1).value.should_not == 'xyzxyz'
@@ -132,7 +129,7 @@ describe Rspreadsheet::Row do
132
129
  duplication_hash = xmlattrs.inject(Hash.new(0)){ |h,e| h[e] += 1; h }
133
130
  duplication_hash.each { |k,v| v.should_not >1 } # should not contain duplicates
134
131
  end
135
- it 'out of bount automagically generated row pick up values when created' do
132
+ it 'out of bound automagically generated row pick up values when created' do
136
133
  @row1 = @sheet1.rows(23)
137
134
  @row2 = @sheet1.rows(23)
138
135
  @row2.cells(5).value = 'hojala'
@@ -145,6 +142,65 @@ describe Rspreadsheet::Row do
145
142
  nec = @sheet2.rows(19).nonemptycells
146
143
  nec.collect{ |c| c.coordinates}.should == [[19,6]]
147
144
  end
145
+ it 'is the same object no matter when you access it' do
146
+ @row1 = @sheet2.rows(5)
147
+ @row2 = @sheet2.rows(5)
148
+ @row1.should equal(@row2)
149
+ end
150
+ it 'reports good range of coordinates for repeated rows' do
151
+ @row2 = @sheet2.rows(15)
152
+ @row2.mode.should == :repeated
153
+ @row2.range.should == (14..18)
154
+
155
+ @sheet1.rows(15).detach
156
+
157
+ @sheet1.rows(2).repeated?.should == true
158
+ @sheet1.rows(2).range.should == (1..14)
159
+
160
+ @sheet1.rows(22).repeated?.should == true
161
+ @sheet1.rows(22).range.should == (16..Float::INFINITY)
162
+ end
163
+ it 'shifts rows if new one is added in the middle' do
164
+ @sheet1.rows(15).detach
165
+ @sheet1.rows(20).detach
166
+ @row = @sheet1.rows(16)
167
+
168
+ @row.range.should == (16..19)
169
+ @row.rowi.should == 16
170
+
171
+ @sheet1.insert_row_above(7)
172
+ @sheet1.rows(17).range.should == (17..20)
173
+ @row.range.should == (17..20)
174
+ @row.rowi.should == 17
175
+ @sheet1.rows(17).should equal(@row)
176
+ end
177
+ it 'inserted has correct class' do # based on real error
178
+ @sheet2.insert_row_above(1)
179
+ @sheet2.rows(1).should be_kind_of(Rspreadsheet::Row)
180
+ end
181
+ it 'can be deleted' do
182
+ @sheet1[15,4]='data'
183
+ @row = @sheet1.rows(15)
184
+ @row.invalid_reference?.should be false
185
+ @row.delete
186
+ @row.invalid_reference?.should be true
187
+ expect { @row.cells(4) }.to raise_error
188
+ @sheet1.rows(15).invalid_reference?.should be false # this is former line 16
189
+ end
190
+ it 'shifts rows if row is deleted' do
191
+ @row = @sheet1.rows(15)
192
+ @row[1] = 'data1'
193
+ @row[1].should eq 'data1'
194
+ @row.rowi.should == 15
195
+
196
+ @sheet1.rows(7).delete
197
+
198
+ @row[1].should eq 'data1'
199
+ @row.rowi.should == 14
200
+
201
+ @sheet1.rows(14).should be @row
202
+ @sheet1.rows(14).cells(1).value.should eq 'data1'
203
+ end
148
204
  end
149
205
 
150
206
 
@@ -70,6 +70,38 @@ describe Rspreadsheet do
70
70
  book = Rspreadsheet.new
71
71
  book.create_worksheet
72
72
  end
73
+ it 'examples from README file are working' do
74
+ skip 'not implemented yet'; pending
75
+ =begin
76
+
77
+ book = Rspreadsheet.open($test_filename)
78
+ sheet = book.worksheets[1]
79
+ sheet.B5 = 'cell value'
80
+
81
+ sheet.B5.should eq 'cell value'
82
+ sheet[5,2].should eq 'cell value'
83
+ sheet.rows(5).cells(2).value.should eq 'cell value'
84
+
85
+ expect {
86
+ sheet.F5 = 'text'
87
+ sheet[5,2] = 7
88
+ sheet.cells(5,2).value = 1.78
89
+
90
+ sheet.cells(5,2).format.bold = true
91
+ sheet.cells(5,2).format.background_color = '#FF0000'
92
+ }.not_to raise_error
93
+
94
+ sheet.rows(4).cellvalues.sum.should eq 4+7*4
95
+ sheet.rows(5).cells.sum{ |cell| cell.value }.should eq 4+7*4
96
+
97
+ total = 0
98
+ sheet.rows.each do |row|
99
+ expect {"Sponsor #{row[1]} with email #{row(2)} has donated #{row(3)} USD." }.not_to raise_error
100
+ total += row[1]
101
+ end
102
+ total.should eq 99
103
+ =end
104
+ end
73
105
  end
74
106
 
75
107
 
data/spec/testfile1.ods CHANGED
Binary file
@@ -7,10 +7,9 @@ describe Rspreadsheet::Worksheet do
7
7
  it 'contains nonempty xml in rows for testfile' do
8
8
  @sheet.rows(1).xmlnode.elements.size.should be >1
9
9
  end
10
- it 'uses detach_subnode_respect_repeated well' do
11
- @xmlnode = @sheet.xmlnode
12
- nod = @sheet.detach_subnode_respect_repeated(@xmlnode, 50, {:xml_items_node_name => 'table-row', :xml_repeated_attribute => 'number-rows-repeated'})
13
- @sheet.detach_subnode_respect_repeated(nod, 12, {:xml_items_node_name => 'table-cell', :xml_repeated_attribute => 'number-columns-repeated'})
10
+ it 'uses detach_my_subnode_respect_repeated well' do
11
+ @sheet.detach_my_subnode_respect_repeated(50, {:xml_items_node_name => 'table-row', :xml_repeated_attribute => 'number-rows-repeated'})
12
+ @sheet.rows(50).detach_my_subnode_respect_repeated(12, {:xml_items_node_name => 'table-cell', :xml_repeated_attribute => 'number-columns-repeated'})
14
13
  end
15
14
  end
16
15
 
@@ -54,4 +53,7 @@ describe Rspreadsheet::Worksheet do
54
53
  @sheet[0,0].should == nil
55
54
  @sheet[999,999].should == nil
56
55
  end
56
+ it 'returns nil with negative index' do
57
+ @sheet.rows(-1).should == nil
58
+ end
57
59
  end
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.2.0
4
+ version: 0.2.3
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: 2014-11-10 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libxml-ruby
@@ -160,7 +160,10 @@ extensions: []
160
160
  extra_rdoc_files: []
161
161
  files:
162
162
  - ".coveralls.yml"
163
+ - ".directory"
163
164
  - ".gitignore"
165
+ - ".kateproject"
166
+ - ".kateproject.d/notes.txt"
164
167
  - ".travis.yml"
165
168
  - COPYING.txt
166
169
  - DEVEL_BLOG.md
@@ -173,7 +176,6 @@ files:
173
176
  - investigate.rb
174
177
  - lib/class_extensions.rb
175
178
  - lib/rspreadsheet.rb
176
- - lib/rspreadsheet/.row.rb.kate-swp.bak
177
179
  - lib/rspreadsheet/cell.rb
178
180
  - lib/rspreadsheet/empty_file_template.ods
179
181
  - lib/rspreadsheet/empty_file_template.old.ods
@@ -182,7 +184,9 @@ files:
182
184
  - lib/rspreadsheet/version.rb
183
185
  - lib/rspreadsheet/workbook.rb
184
186
  - lib/rspreadsheet/worksheet.rb
187
+ - lib/rspreadsheet/xml_tied.rb
185
188
  - reinstall.sh
189
+ - reinstall2.sh
186
190
  - rspreadsheet.gemspec
187
191
  - spec/cell_spec.rb
188
192
  - spec/row_spec.rb
@@ -192,7 +196,6 @@ files:
192
196
  - spec/tools_spec.rb
193
197
  - spec/workbook_spec.rb
194
198
  - spec/worksheet_spec.rb
195
- - spec/xml_tied_array_spec.rb
196
199
  homepage: https://github.com/gorn/rspreadsheet
197
200
  licenses:
198
201
  - GPL
@@ -227,4 +230,3 @@ test_files:
227
230
  - spec/tools_spec.rb
228
231
  - spec/workbook_spec.rb
229
232
  - spec/worksheet_spec.rb
230
- - spec/xml_tied_array_spec.rb
Binary file
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rspreadsheet::XmlTiedArray do
4
- before do
5
- end
6
- it 'can get items out correctly' do
7
- end
8
-
9
- end