rspreadsheet 0.0.5 → 0.0.6

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.
data/spec/row_spec.rb ADDED
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rspreadsheet::Row do
4
+ before do
5
+ @sheet1 = Rspreadsheet.new.create_worksheet
6
+ @sheet2 = Rspreadsheet.new($test_filename).worksheets[1]
7
+ end
8
+ it 'allows access to cells in a row' do
9
+ @row = @sheet2.rows(1)
10
+ @c = @row.cells(1)
11
+ @c.value = 3
12
+ @c.value.should == 3
13
+ end
14
+ it 'creates minimal row on demand, which contains correctly namespaced attributes only'do
15
+ @sheet1.rows(1).cells(2).value = 'nejakydata'
16
+ @row = @sheet1.rows(1)
17
+ @xmlnode = @row.xmlnode
18
+ @xmlnode.namespaces.to_a.size.should >5
19
+ @xmlnode.namespaces.namespace.should_not be_nil
20
+ @xmlnode.namespaces.namespace.prefix.should == 'table'
21
+ end
22
+ it 'cells in row are settable through sheet' do
23
+ @sheet1.rows(9).add_cell
24
+ @sheet1.rows(9).cells(1).value = 2
25
+ @sheet1.rows(9).cells(1).value.should == 2
26
+
27
+ @sheet1.rows(7).add_cell
28
+ @sheet1.rows(7).cells(1).value = 7
29
+ @sheet1.rows(7).cells(1).value.should == 7
30
+
31
+ @sheet1.rows(5).cells(1).value = 5
32
+ @sheet1.rows(5).cells(1).value.should == 5
33
+
34
+ (2..5).each { |i| @sheet1.rows(3).cells(i).value = i }
35
+ (2..5).each { |i|
36
+ a = @sheet1.rows(3)
37
+ c = a.cells(i)
38
+ c.value.should == i
39
+ }
40
+ end
41
+ it 'is found even in empty sheets' do
42
+ @sheet1.rows(5).should be_kind_of(Rspreadsheet::Row)
43
+ @sheet1.rows(25).should be_kind_of(Rspreadsheet::Row)
44
+ @sheet1.cells(10,10).value = 'ahoj'
45
+ @sheet1.rows(9).should be_kind_of(Rspreadsheet::Row)
46
+ @sheet1.rows(10).should be_kind_of(Rspreadsheet::Row)
47
+ @sheet1.rows(11).should be_kind_of(Rspreadsheet::Row)
48
+ end
49
+ it 'detachment works as expected' do
50
+ @sheet1.rows(5).detach
51
+ @sheet1.rows(5).repeated?.should == false
52
+ @sheet1.rows(5).repeated.should == 1
53
+ @sheet1.rows(5).xmlnode.should_not == nil
54
+ @sheet1.rows(3).repeated?.should == true
55
+ @sheet1.rows(3).repeated.should == 4
56
+ @sheet1.rows(3).xmlnode.should_not == nil
57
+ @table_ns_href = "urn:oasis:names:tc:opendocument:xmlns:table:1.0"
58
+ @sheet1.rows(3).xmlnode.attributes.get_attribute_ns(@table_ns_href,'number-rows-repeated').value.should == '4'
59
+ end
60
+ it 'by assigning value, the repeated row is automatically detached' do
61
+ row = @sheet1.rows(5)
62
+ row.detach
63
+ @table_ns_href = "urn:oasis:names:tc:opendocument:xmlns:table:1.0"
64
+
65
+ @sheet1.rows(5).style_name = 'newstylename'
66
+ @sheet1.rows(5).xmlnode.attributes.get_attribute_ns(@table_ns_href,'style-name').value.should == 'newstylename'
67
+
68
+ @sheet1.rows(17).style_name = 'newstylename2'
69
+ @sheet1.rows(17).xmlnode.attributes.get_attribute_ns(@table_ns_href,'style-name').value.should == 'newstylename2'
70
+ end
71
+ it 'ignores negative any zero row indexes' do
72
+ @sheet1.rows(0).should be_nil
73
+ @sheet1.rows(-78).should be_nil
74
+ end
75
+ it 'has correct rowindex' do
76
+ @sheet1.rows(5).detach
77
+ (4..6).each do |i|
78
+ @sheet1.rows(i).row.should == i
79
+ end
80
+ end
81
+ it 'can open ods testfile and read its content' do
82
+ book = Rspreadsheet.new($test_filename)
83
+ s = book.worksheets[1]
84
+ (1..10).each do |i|
85
+ s.rows(i).should be_kind_of(Rspreadsheet::Row)
86
+ s.rows(i).repeated.should == 1
87
+ s.rows(i).used_range.size>0
88
+ end
89
+ s[1,2].should === 'text'
90
+ s[2,2].should === Date.new(2014,1,1)
91
+ end
92
+ it 'normalizes to itself if single line' do
93
+ @sheet1.rows(5).detach
94
+ @sheet1.rows(5).cells(4).value='test'
95
+ @sheet1.rows(5).normalize
96
+ @sheet1.rows(5).cells(4).value.should == 'test'
97
+ end
98
+ it 'cell manipulation does not contain attributes without namespace nor doubled attributes' do # inspired by a real bug regarding namespaces manipulation
99
+ @sheet2.rows(1).xmlnode.attributes.each { |attr| attr.ns.should_not be_nil}
100
+ @sheet2.rows(1).cells(1).value.should_not == 'xyzxyz'
101
+ @sheet2.rows(1).cells(1).value ='xyzxyz'
102
+ @sheet2.rows(1).cells(1).value.should == 'xyzxyz'
103
+
104
+ ## attributes have namespaces
105
+ @sheet2.rows(1).xmlnode.attributes.each { |attr| attr.ns.should_not be_nil}
106
+
107
+ ## attributes are not douubled
108
+ xmlattrs = @sheet2.rows(1).xmlnode.attributes.to_a.collect{ |a| [a.ns.andand.prefix.to_s,a.name].reject{|x| x.empty?}.join(':')}
109
+ duplication_hash = xmlattrs.inject(Hash.new(0)){ |h,e| h[e] += 1; h }
110
+ duplication_hash.each { |k,v| v.should_not >1 } # should not contain duplicates
111
+ end
112
+ it 'out of bount automagically generated row pick up values when created' do
113
+ @row1 = @sheet1.rows(23)
114
+ @row2 = @sheet1.rows(23)
115
+ @row2.cells(5).value = 'hojala'
116
+ @row1.cells(5).value.should == 'hojala'
117
+ end
118
+ it 'nonempty cells work properly' do
119
+ nec = @sheet2.rows(1).nonemptycells
120
+ nec.collect{ |c| [c.row,c.col]}.should == [[1,1],[1,2]]
121
+
122
+ nec = @sheet2.rows(19).nonemptycells
123
+ nec.collect{ |c| [c.row,c.col]}.should == [[19,6]]
124
+ end
125
+ end
126
+
127
+
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- $test_filename = './spec/testfile1.ods'
4
-
5
3
  describe Rspreadsheet::Tools do
6
- it '=Converts correctly cell adresses' do
4
+ it 'converts correctly cell adresses' do
7
5
  Rspreadsheet::Tools.convert_cell_address('A1') [0].should == 1
8
6
  Rspreadsheet::Tools.convert_cell_address('A1')[1].should == 1
9
7
  Rspreadsheet::Tools.convert_cell_address('C5')[0].should == 5
@@ -11,24 +9,10 @@ describe Rspreadsheet::Tools do
11
9
  end
12
10
  end
13
11
 
14
- describe Rspreadsheet::Tools::SparseRepeatedArray do
15
- before do
16
- # @a = Rspreadsheet::Tools::SparseRepeatedArray.new()
17
- end
18
- # Float::INFINITY
19
- its 'set values can be read back unchanged' do
20
- skip
21
- @a[3..5]='test'
22
- @a[4].should == 'test'
23
- end
24
- end
25
-
26
12
  describe Rspreadsheet do
27
13
  it 'can open ods testfile and reads its content correctly' do
28
14
  book = Rspreadsheet.new($test_filename)
29
- book.worksheets[0].should_not == nil
30
- book.worksheets[0].class.should == Rspreadsheet::Worksheet
31
- s = book.worksheets[0]
15
+ s = book.worksheets[1]
32
16
  (1..10).each do |i|
33
17
  s[i,1].should === i
34
18
  end
@@ -43,8 +27,8 @@ describe Rspreadsheet do
43
27
 
44
28
  book1 = Rspreadsheet.new($test_filename) # now open both again
45
29
  book2 = Rspreadsheet.new(tmp_filename)
46
- @sheet1 = book1.worksheets[0]
47
- @sheet2 = book2.worksheets[0]
30
+ @sheet1 = book1.worksheets[1]
31
+ @sheet2 = book2.worksheets[1]
48
32
 
49
33
  @sheet1.nonemptycells.each do |cell| # and test identity
50
34
  @sheet2[cell.row,cell.col].should == cell.value
@@ -63,15 +47,23 @@ describe Rspreadsheet do
63
47
  @content_xml2 = Zip::File.open(tmp_filename) do |zip|
64
48
  LibXML::XML::Document.io zip.get_input_stream('content.xml')
65
49
  end
50
+
51
+ @content_xml2.root.first_diff(@content_xml1.root).should be_nil
52
+ @content_xml1.root.first_diff(@content_xml2.root).should be_nil
53
+
66
54
  @content_xml1.root.equals?(@content_xml2.root).should == true
67
55
  end
68
56
  it 'when open and save file modified, than the file is different' do
69
57
  tmp_filename = '/tmp/testfile1.ods' # first delete temp file
70
58
  File.delete(tmp_filename) if File.exists?(tmp_filename)
71
59
  book = Rspreadsheet.new($test_filename) # than open test file
72
- book.worksheets[0][1,1].should_not == 'xyzxyz'
73
- book.worksheets[0][1,1]='xyzxyz'
74
- book.worksheets[0][1,1].should == 'xyzxyz'
60
+ book.worksheets[1].rows(1).cells(1).value.should_not == 'xyzxyz'
61
+ book.worksheets[1].rows(1).cells(1).value ='xyzxyz'
62
+ book.worksheets[1].rows(1).cells(1).value.should == 'xyzxyz'
63
+
64
+ # book.worksheets[1][1,1].should_not == 'xyzxyz'
65
+ # book.worksheets[1][1,1]='xyzxyz'
66
+ # book.worksheets[1][1,1].should == 'xyzxyz'
75
67
  book.save(tmp_filename) # and save it as temp file
76
68
 
77
69
  # now compare them
@@ -92,91 +84,30 @@ describe Rspreadsheet do
92
84
  end
93
85
  end
94
86
 
95
- describe Rspreadsheet::Cell do
96
- before do
97
- book1 = Rspreadsheet.new
98
- @sheet1 = book1.create_worksheet
99
- @sheet1[0,0] = 'text'
100
- book2 = Rspreadsheet.new($test_filename)
101
- @sheet2 = book2.worksheets[0]
102
- end
103
- it 'contains good row and col coordinates' do
104
- @cell = @sheet1.cells(1,3)
105
- @cell.row.should == 1
106
- @cell.col.should == 3
107
- @cell.coordinates.should == [1,3]
108
-
109
- @cell = @sheet2.cells(7,2)
110
- @cell.row.should == 7
111
- @cell.col.should == 2
112
- @cell.coordinates.should == [7,2]
113
- end
114
- it 'can be referenced by more vars and both are synchronized' do
115
- @cell = @sheet1.cells(1,1)
116
- @sheet1[1,1] = 'novinka'
117
- @cell.value.should == 'novinka'
118
- end
119
- it 'can be modified by more ways and all are identical' do
120
- @cell = @sheet1.cells(2,2)
121
- @sheet1[2,2] = 'zaprve'
122
- @cell.value.should == 'zaprve'
123
- @sheet1.cells(2,2).value = 'zadruhe'
124
- @cell.value.should == 'zadruhe'
125
- @sheet1.B2 = 'zatreti'
126
- @cell.value.should == 'zatreti'
127
- end
128
- it 'can include links' do
129
- @sheet2.A12.should == '[http://example.org/]'
130
- end
131
- it 'contains good row and col coordinates even after table:number-columns-repeated cells' do
132
- skip
133
- @cell = @sheet2.cells(13,5)
134
- @cell.value.should == 'afterrepeated'
135
- @cell.row.should == 13
136
- @cell.col.should == 5
137
- end
138
- end
139
87
 
140
- describe Rspreadsheet::Worksheet do
141
- before do
142
- book = Rspreadsheet.new
143
- @sheet = book.create_worksheet
144
- end
145
- it 'remembers the value stored to A1 cell' do
146
- @sheet[1,1].should == nil
147
- @sheet[1,1] = 'test text'
148
- @sheet[1,1].class.should == String
149
- @sheet[1,1].should == 'test text'
150
- end
151
- it 'value stored to A1 is accesible using different syntax' do
152
- @sheet[1,1] = 'test text'
153
- @sheet[1,1].should == 'test text'
154
- @sheet.cells(1,1).value.should == 'test text'
155
- end
156
- it 'makes Cell object accessible' do
157
- @sheet.cells(1,1).value = 'test text'
158
- @sheet.cells(1,1).class.should == Rspreadsheet::Cell
159
- end
160
- it 'has name, which can be changed and is remembered' do
161
- @sheet.name.should be(nil)
162
- @sheet.name = 'Icecream'
163
- @sheet.name.should == 'Icecream'
164
- @sheet.name = 'Cofee'
165
- @sheet.name.should == 'Cofee'
166
- end
167
- end
168
88
 
169
- describe Rspreadsheet::Row do
170
- before do
171
- book1 = Rspreadsheet.new
172
- @sheet1 = book1.create_worksheet
173
- end
174
- it 'allows access to cells in a row' do
175
- (2..5).each { |i| @sheet1[7,i] = i }
176
- (2..5).each { |i|
177
- a = @sheet1.rows(7)
178
- c = a.cells(i)
179
- c.value.should == i
180
- }
181
- end
182
- end
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,11 @@
1
+ RSpec.configure do |c|
2
+ c.fail_fast = true
3
+ # c.warnings = true
4
+ end
5
+
1
6
  require 'coveralls'
2
7
  Coveralls.wear!
3
8
 
9
+ $test_filename = './spec/testfile1.ods'
10
+
4
11
  require 'rspreadsheet'
data/spec/testfile1.ods CHANGED
Binary file
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rspreadsheet::Workbook do
4
+ it 'has correct number of sheets' do
5
+ book = Rspreadsheet.new($test_filename)
6
+ book.worksheets_count.should == 1
7
+ book.worksheets[0].should be_nil
8
+ book.worksheets[1].should be_kind_of(Rspreadsheet::Worksheet)
9
+ book.worksheets[2].should be_nil
10
+ book.worksheets[nil].should be_nil
11
+ end
12
+ it 'freshly created has correctly namespaced xmlnode' do
13
+ @xmlnode = Rspreadsheet.new.xmlnode
14
+ @xmlnode.namespaces.to_a.size.should >5
15
+ @xmlnode.namespaces.find_by_prefix('office').should_not be_nil
16
+ @xmlnode.namespaces.find_by_prefix('table').should_not be_nil
17
+ @xmlnode.namespaces.namespace.prefix.should == 'office'
18
+ end
19
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rspreadsheet::Worksheet do
4
+ before do
5
+ @sheet = Rspreadsheet.new($test_filename).worksheets[1]
6
+ end
7
+ it 'contains nonempty xml in rows for testfile' do
8
+ @sheet.rows(1).xmlnode.elements.size.should be >1
9
+ end
10
+ it 'freshly created has correctly namespaced xmlnode' do
11
+ @spreadsheet = Rspreadsheet.new
12
+ @spreadsheet.create_worksheet
13
+ @xmlnode = @spreadsheet.worksheets[1].xmlnode
14
+ @xmlnode.namespaces.to_a.size.should >5
15
+ @xmlnode.namespaces.find_by_prefix('office').should_not be_nil
16
+ @xmlnode.namespaces.find_by_prefix('table').should_not be_nil
17
+ @xmlnode.namespaces.namespace.should_not be_nil
18
+ @xmlnode.namespaces.namespace.prefix.should == 'table'
19
+ end
20
+
21
+ end
22
+
23
+ describe Rspreadsheet::Worksheet do
24
+ before do
25
+ book = Rspreadsheet.new
26
+ @sheet = book.create_worksheet
27
+ end
28
+ it 'remembers the value stored to A1 cell' do
29
+ @sheet[1,1].should == nil
30
+ @sheet[1,1] = 'test text'
31
+ @sheet[1,1].class.should == String
32
+ @sheet[1,1].should == 'test text'
33
+ end
34
+ it 'value stored to A1 is accesible using different syntax' do
35
+ @sheet[1,1] = 'test text'
36
+ @sheet[1,1].should == 'test text'
37
+ @sheet.cells(1,1).value.should == 'test text'
38
+ end
39
+ it 'makes Cell object accessible' do
40
+ @sheet.cells(1,1).value = 'test text'
41
+ @sheet.cells(1,1).class.should == Rspreadsheet::Cell
42
+ end
43
+ it 'has name, which can be changed and is remembered' do
44
+ @sheet.name.should be(nil)
45
+ @sheet.name = 'Icecream'
46
+ @sheet.name.should == 'Icecream'
47
+ @sheet.name = 'Cofee'
48
+ @sheet.name.should == 'Cofee'
49
+ end
50
+ 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.0.5
4
+ version: 0.0.6
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-07-26 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libxml-ruby
@@ -95,33 +95,33 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '2'
97
97
  - !ruby/object:Gem::Dependency
98
- name: coveralls
98
+ name: pry-nav
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '0.7'
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '0.7'
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: test_notifier
112
+ name: coveralls
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '2.0'
117
+ version: '0.7'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '2.0'
124
+ version: '0.7'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: guard
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -169,19 +169,25 @@ files:
169
169
  - LICENSE.md
170
170
  - README.md
171
171
  - Rakefile
172
+ - investigate.rb
172
173
  - lib/class_extensions.rb
173
174
  - lib/rspreadsheet.rb
174
175
  - lib/rspreadsheet/cell.rb
175
176
  - lib/rspreadsheet/empty_file_template.ods
177
+ - lib/rspreadsheet/empty_file_template.old.ods
176
178
  - lib/rspreadsheet/row.rb
177
179
  - lib/rspreadsheet/tools.rb
178
180
  - lib/rspreadsheet/version.rb
179
181
  - lib/rspreadsheet/workbook.rb
180
182
  - lib/rspreadsheet/worksheet.rb
181
183
  - rspreadsheet.gemspec
184
+ - spec/cell_spec.rb
185
+ - spec/row_spec.rb
182
186
  - spec/rspreadsheet_spec.rb
183
187
  - spec/spec_helper.rb
184
188
  - spec/testfile1.ods
189
+ - spec/workbook_spec.rb
190
+ - spec/worksheet_spec.rb
185
191
  homepage: https://github.com/gorn/rspreadsheet
186
192
  licenses:
187
193
  - GPL
@@ -208,6 +214,10 @@ specification_version: 4
208
214
  summary: Manipulating spreadsheets with Ruby (read / create / modify OpenDocument
209
215
  Spreadsheet).
210
216
  test_files:
217
+ - spec/cell_spec.rb
218
+ - spec/row_spec.rb
211
219
  - spec/rspreadsheet_spec.rb
212
220
  - spec/spec_helper.rb
213
221
  - spec/testfile1.ods
222
+ - spec/workbook_spec.rb
223
+ - spec/worksheet_spec.rb