rspreadsheet 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DEVEL_BLOG.md +6 -5
- data/GUIDE.md +3 -0
- data/lib/rspreadsheet/cell.rb +33 -21
- data/lib/rspreadsheet/row.rb +7 -3
- data/lib/rspreadsheet/version.rb +1 -1
- data/lib/rspreadsheet/workbook.rb +1 -1
- data/lib/rspreadsheet/worksheet.rb +3 -3
- data/reinstall.sh +6 -0
- data/rspreadsheet.gemspec +2 -2
- data/spec/cell_spec.rb +13 -0
- data/spec/rspreadsheet_spec.rb +1 -1
- data/spec/worksheet_spec.rb +5 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b667a14fc5845f86995ec8f260650b47f92fc8b8
|
4
|
+
data.tar.gz: d8311461aeb22d2d801f8615bc8d3e43a1b35707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e742ce5a232d4d1e4a46c64bbffab4d4607ed3024cb327ad514f9c27f30053d86e2edaef6b3755927136719f667ea9076b9c79f35baf166431315e1fde0e18b7
|
7
|
+
data.tar.gz: 778a31e6b50ee4d15873ec6c416361f0f4ea24476608b2555004fb54fac070117612b4bff1747678ea6a25a6e3001176bcdb22866891a6ed13f6889074a5e50a
|
data/DEVEL_BLOG.md
CHANGED
@@ -31,16 +31,17 @@ Guiding ideas
|
|
31
31
|
|
32
32
|
### Local manual testing and releasing (to github released, ).
|
33
33
|
|
34
|
+
gem build rspreadsheet.gemspec
|
35
|
+
sudo gem install rspreadsheet-x.y.z.gem
|
36
|
+
gem push rspreadsheet-x.y.z.gem
|
37
|
+
|
38
|
+
alternative way using ``rake`` command - release is more automatic
|
39
|
+
|
34
40
|
* ``rake build`` - builds the gem to pkg directory.
|
35
41
|
* ``sudo rake install`` - If this fails with "mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h" you may want to ``sudo aptitude install ruby-dev``
|
36
42
|
* Now can locally and manually use/test the gem. This should not be replacement for automated testing.
|
37
43
|
* ``rake release`` - creates a version tag in git and pushes the code to github + Rubygems. After this is succesfull the new version appears as release in Github and RubyGems.
|
38
44
|
|
39
|
-
alternative way using ``gem`` command
|
40
|
-
|
41
|
-
gem build rspreadsheet.gemspec
|
42
|
-
sudo gem install rspreadsheet-x.y.z.gem
|
43
|
-
gem push rspreadsheet-x.y.z.gem
|
44
45
|
|
45
46
|
|
46
47
|
### Naming conventions
|
data/GUIDE.md
CHANGED
@@ -32,6 +32,9 @@ sheet.cells(1,1).value = value
|
|
32
32
|
|
33
33
|
p sheet.A1.class # => Rspreadsheet::Cell
|
34
34
|
|
35
|
+
# relative cells
|
36
|
+
sheet.cells(4,7).relative(-1,0) # => cell 3,7
|
37
|
+
|
35
38
|
# build the top five list
|
36
39
|
(1..5).each { |i| sheet[i,1] = i }
|
37
40
|
sheet.columns(1).format.bold = true
|
data/lib/rspreadsheet/cell.rb
CHANGED
@@ -23,10 +23,11 @@ class Cell
|
|
23
23
|
def ns_office; @parent_row.xmlnode.doc.root.namespaces.find_by_prefix('office') end
|
24
24
|
def ns_text; @parent_row.xmlnode.doc.root.namespaces.find_by_prefix('text') end
|
25
25
|
def to_s; value end
|
26
|
-
def
|
27
|
-
def
|
26
|
+
def cell_xml; self.xmlnode.to_s; end
|
27
|
+
def xml; self.xmlnode.children.first.andand.inner_xml end
|
28
28
|
def coordinates; [row,col]; end
|
29
29
|
def row; @parent_row.row; end
|
30
|
+
def worksheet; @parent_row.worksheet; end
|
30
31
|
def value
|
31
32
|
gt = guess_cell_type
|
32
33
|
if (@mode == :regular) or (@mode == @repeated)
|
@@ -87,7 +88,23 @@ class Cell
|
|
87
88
|
def set_type_attribute(typestring)
|
88
89
|
Tools.set_ns_attribute(@xmlnode,'office','value-type',typestring)
|
89
90
|
end
|
90
|
-
|
91
|
+
def type
|
92
|
+
case
|
93
|
+
when guess_cell_type == Float then :float
|
94
|
+
when guess_cell_type == String then :string
|
95
|
+
when guess_cell_type == Date then :date
|
96
|
+
when guess_cell_type == 'percentage' then :percentage
|
97
|
+
when guess_cell_type == nil then :empty
|
98
|
+
else :unknown
|
99
|
+
end
|
100
|
+
end
|
101
|
+
# use this to find node in cell xml. ex. xmlfind('.//text:a') finds all link nodes
|
102
|
+
def xmlfindall(path)
|
103
|
+
xmlnode.find(path)
|
104
|
+
end
|
105
|
+
def xmlfindfirst(path)
|
106
|
+
xmlfindall(path).first
|
107
|
+
end
|
91
108
|
# based on @xmlnode and optionally value which is about to be assigned, guesses which type the result should be
|
92
109
|
def guess_cell_type(avalue=nil)
|
93
110
|
# try guessing by value
|
@@ -106,7 +123,7 @@ class Cell
|
|
106
123
|
when 'float' then Float
|
107
124
|
when 'string' then String
|
108
125
|
when 'date' then Date
|
109
|
-
when 'percentage' then
|
126
|
+
when 'percentage' then :percentage
|
110
127
|
else
|
111
128
|
if @xmlnode.children.size == 0
|
112
129
|
nil
|
@@ -141,26 +158,21 @@ class Cell
|
|
141
158
|
def inspect
|
142
159
|
"#<Cell:[#{row},#{col}]=#{value}(#{guess_cell_type.to_s})"
|
143
160
|
end
|
161
|
+
def relative(rowdiff,coldiff)
|
162
|
+
worksheet.cells(self.row+rowdiff, self.col+coldiff)
|
163
|
+
end
|
144
164
|
end
|
145
165
|
|
146
166
|
end
|
147
167
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
# coli = 1
|
158
|
-
# row_source_node.elements.select{ |node| node.name == 'table-cell'}.each do |cell_source_node|
|
159
|
-
# initialize_cell(rowi,coli,cell_source_node)
|
160
|
-
# coli += 1
|
161
|
-
# end
|
162
|
-
# rowi += 1
|
163
|
-
# end
|
164
|
-
# end
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
165
177
|
|
166
178
|
|
data/lib/rspreadsheet/row.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require('rspreadsheet/cell')
|
2
|
-
|
2
|
+
require('forwardable')
|
3
|
+
|
3
4
|
|
4
5
|
# Currently this is only syntax sugar for cells and contains no functionality
|
5
6
|
|
6
7
|
module Rspreadsheet
|
7
8
|
|
8
9
|
class RowArray
|
9
|
-
def initialize(aworksheet_node)
|
10
|
+
def initialize(aworksheet,aworksheet_node)
|
11
|
+
@worksheet = aworksheet
|
10
12
|
@worksheet_node = aworksheet_node
|
11
13
|
|
12
14
|
# initialize @rowgroups from @worksheet_node
|
@@ -106,7 +108,7 @@ class RowArray
|
|
106
108
|
@rowgroups[index..index]=replaceby
|
107
109
|
result
|
108
110
|
end
|
109
|
-
|
111
|
+
def worksheet; @worksheet end
|
110
112
|
private
|
111
113
|
def get_row_group_index(rowi)
|
112
114
|
@rowgroups.find_index{ |rowgroup| rowgroup.range.cover?(rowi) }
|
@@ -119,6 +121,8 @@ class Row
|
|
119
121
|
def self.empty_row_node
|
120
122
|
LibXML::XML::Node.new('table-row',nil, Tools.get_namespace('table'))
|
121
123
|
end
|
124
|
+
def worksheet; @parent_array.worksheet end
|
125
|
+
def parent_array; @parent_array end # for debug only
|
122
126
|
end
|
123
127
|
|
124
128
|
class RowWithXMLNode < Row
|
data/lib/rspreadsheet/version.rb
CHANGED
@@ -26,7 +26,7 @@ class Workbook
|
|
26
26
|
Zip::File.open(@filename) do |zip|
|
27
27
|
# it is easy, because @xmlnode in in sync with contents all the time
|
28
28
|
zip.get_output_stream('content.xml') do |f|
|
29
|
-
f.write @content_xml
|
29
|
+
f.write @content_xml.to_s(:indent => false)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -23,7 +23,7 @@ class Worksheet
|
|
23
23
|
end
|
24
24
|
|
25
25
|
## initialize rows
|
26
|
-
@spredsheetrows=RowArray.new(
|
26
|
+
@spredsheetrows=RowArray.new(self,@xmlnode)
|
27
27
|
end
|
28
28
|
def cells(r,c)
|
29
29
|
rows(r).andand.cells(c)
|
@@ -36,10 +36,10 @@ class Worksheet
|
|
36
36
|
end
|
37
37
|
## syntactic sugar follows
|
38
38
|
def [](r,c)
|
39
|
-
cells(r,c).value
|
39
|
+
cells(r,c).andand.value
|
40
40
|
end
|
41
41
|
def []=(r,c,avalue)
|
42
|
-
cells(r,c).value=avalue
|
42
|
+
cells(r,c).andand.value=avalue
|
43
43
|
end
|
44
44
|
# allows syntax like sheet.F15
|
45
45
|
def method_missing method_name, *args, &block
|
data/reinstall.sh
ADDED
data/rspreadsheet.gemspec
CHANGED
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.5"
|
29
29
|
spec.add_development_dependency "rake", '~>0.9'
|
30
30
|
# testig - see http://bit.ly/1n5yM51
|
31
|
-
spec.add_development_dependency "rspec", '~>2'
|
32
|
-
spec.add_development_dependency 'pry-nav'
|
31
|
+
spec.add_development_dependency "rspec", '~>2' # testing
|
32
|
+
spec.add_development_dependency 'pry-nav', '~>0' # enables pry 'next', 'step' commands
|
33
33
|
|
34
34
|
# optional and testing
|
35
35
|
spec.add_development_dependency "coveralls", '~>0.7'
|
data/spec/cell_spec.rb
CHANGED
@@ -46,4 +46,17 @@ describe Rspreadsheet::Cell do
|
|
46
46
|
@sheet2.cells(2,-5).should be(nil)
|
47
47
|
@sheet2.cells(-2,-5).should be(nil)
|
48
48
|
end
|
49
|
+
it 'has nonempty parents' do
|
50
|
+
@cell = @sheet2.cells(13,5)
|
51
|
+
@cell.parent_row.should_not be_nil
|
52
|
+
@cell.worksheet.should_not be_nil
|
53
|
+
|
54
|
+
@cell = @sheet1.cells(2,2)
|
55
|
+
@cell.parent_row.should_not be_nil
|
56
|
+
@cell.worksheet.should_not be_nil
|
57
|
+
end
|
58
|
+
it 'handles relative correctly' do
|
59
|
+
@sheet2.cells(3,3).relative(-1,+2).coordinates.should == [2,5]
|
60
|
+
@sheet2.cells(3,3).relative(0,0).coordinates.should == [3,3]
|
61
|
+
end
|
49
62
|
end
|
data/spec/rspreadsheet_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Rspreadsheet::Tools do
|
4
4
|
it 'converts correctly cell adresses' do
|
5
|
-
Rspreadsheet::Tools.convert_cell_address('A1')
|
5
|
+
Rspreadsheet::Tools.convert_cell_address('A1')[0].should == 1
|
6
6
|
Rspreadsheet::Tools.convert_cell_address('A1')[1].should == 1
|
7
7
|
Rspreadsheet::Tools.convert_cell_address('C5')[0].should == 5
|
8
8
|
Rspreadsheet::Tools.convert_cell_address('C5')[1].should == 3
|
data/spec/worksheet_spec.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
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
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libxml-ruby
|
@@ -98,14 +98,14 @@ dependencies:
|
|
98
98
|
name: pry-nav
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
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
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- lib/rspreadsheet/version.rb
|
181
181
|
- lib/rspreadsheet/workbook.rb
|
182
182
|
- lib/rspreadsheet/worksheet.rb
|
183
|
+
- reinstall.sh
|
183
184
|
- rspreadsheet.gemspec
|
184
185
|
- spec/cell_spec.rb
|
185
186
|
- spec/row_spec.rb
|