rspreadsheet 0.2.10 → 0.2.11
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 +40 -8
- data/GUIDE.md +30 -0
- data/README.md +2 -2
- data/lib/{class_extensions.rb → helpers/class_extensions.rb} +0 -0
- data/lib/helpers/configuration.rb +24 -0
- data/lib/rspreadsheet.rb +4 -1
- data/lib/rspreadsheet/version.rb +1 -1
- data/lib/rspreadsheet/workbook.rb +37 -26
- data/lib/rspreadsheet/worksheet.rb +1 -1
- data/lib/rspreadsheet/xml_tied.rb +2 -1
- data/reinstall_local_gem.sh +15 -0
- data/spec/cell_spec.rb +10 -2
- data/spec/row_spec.rb +10 -6
- data/spec/workbook_spec.rb +9 -0
- data/spec/worksheet_spec.rb +77 -58
- metadata +5 -5
- data/reinstall.sh +0 -7
- data/reinstall2.sh +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63cd4006cec7642ea6755fe2c2fde09943c67a17
|
4
|
+
data.tar.gz: dbc0b88c94998ae407fb909219a1832d5ab4c00f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25885b830e8a23088c9d7171117f270d5fb191f08147409be703f93e63354331ab7e016a0666ffccb296266513e3d0688b4b44c20ba79424652908f81728fb49
|
7
|
+
data.tar.gz: 4ad5a10753aaf548d31861d028da97d81ace87d1df753f9e350c393d67a0d9b34ab9e2c0ac5cd420d48a4e76600cadf6edbbeb489c6b4cbe0e7c9dc1d20e4fe1
|
data/DEVEL_BLOG.md
CHANGED
@@ -12,8 +12,44 @@ See [GUIDE.md](GUIDE.md#conventions) for syntax conventions.
|
|
12
12
|
* `sheet.rows(1).cells` returns list of cells objects and `sheet.rows(1).cellvalues` return array of values with nils when empty
|
13
13
|
* implement to_csv
|
14
14
|
* longterm plan - go through other used libraries and try to find out whose syntax could be adopted, so this library is drop in replacement (possibly with some config options) for them
|
15
|
+
* iterative generation like this
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
RSpreadsheet.generate('pricelist.ods') do
|
19
|
+
row 'icecream name', 'price'
|
20
|
+
{ 'Vanilla' => 2, 'Banana' => 3, 'Strawbery' => 2.7 }.each do |icecream, price|
|
21
|
+
row icecream, price
|
22
|
+
row '2x 'icecream, price * 1.8
|
23
|
+
end
|
24
|
+
skip_row
|
25
|
+
row 'Menu made by rspreadsheet', :format => {:font => {:size => 5}}
|
26
|
+
move_to A5
|
27
|
+
cell 'Have a nice day!'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
* possible ideas from [Google Spreadsheet API](https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet) (issue #9). For now just raw list of what could be used
|
32
|
+
* appendRaw(rowContents)
|
33
|
+
* concept of active sheets with methods like - deleteActiveSheet, getActiveSheet, duplicateActiveSheet(), getActiveCell()
|
34
|
+
* `@sheet.delete_column(2), @sheet.delete_columns(from, howmany), @sheet.delete_row(2), ...`
|
35
|
+
* GS API uses `@workbook.deletesheet(@sheet)` but it is nor very ruby way. What about `@worksheet.delete` or `@workbook.delete_sheet(2)` as syntactic shugar to `@workbook.worksheets(2).delete`
|
36
|
+
* getAs(contentType) - Return the data inside this object as a blob converted to the specified content type. Maybe something like `@workbook.worksheets(2).to_pdf` or `@workbook.worksheets(2).to_blob('application/pdf')`. Is there anything like Blob in ruby?
|
37
|
+
* getDataRange() - Returns a Range corresponding to the dimensions in which data is present
|
38
|
+
* setActiveRange(range), setActiveSelection(range) - ? what is the difference
|
39
|
+
* @sheet. getFrozenColumns(), @sheet.getFrozenColumns()
|
40
|
+
* getLastColumn(), getLastRow()
|
41
|
+
* getRange(a1Notation), getRangeByName(name), range.get_values
|
42
|
+
* getRowHeight(rowPosition)
|
43
|
+
* hideColumn(column), unhideColumn(column), insertColumnAfter(afterPosition), insertColumnsAfter(afterPosition, howMany), insertImage(blob, column, row)
|
44
|
+
* moveActiveSheet(pos)
|
45
|
+
* sort(columnPosition,ascending=true) - Sorts a sheet by column.
|
46
|
+
* Range#breakApart() - Break any multi-column cells in the range into individual cells again.
|
47
|
+
* Range#canEdit()
|
48
|
+
* Range#copyTo(destination)
|
49
|
+
* Range#merge() - Merges the cells in the range together into a single block.
|
50
|
+
* @book.sheet_names - Array of names of sheets.
|
15
51
|
|
16
|
-
Guiding ideas
|
52
|
+
##Guiding ideas
|
17
53
|
* xml document is always synchronized with the data. So the save is trivial.
|
18
54
|
* no duplication of data. Objects like RowArray should containg minimum information. This one exists solely to speed up cell search. Taken to extream it is questionable, whether we need such objects at all, it might be possible to always work with xml directly.
|
19
55
|
* all cells and rows only server as proxy. they hold index and worksheet pointer and everytime read or write is done, the xml is newly searched. until there is a xmlnode caching we have no problem
|
@@ -37,11 +73,9 @@ Guiding ideas
|
|
37
73
|
|
38
74
|
### Local testing and releasing (to github and rubygems).
|
39
75
|
|
40
|
-
1.
|
41
|
-
2.
|
42
|
-
3.
|
43
|
-
* ``rake build`` - builds the gem to pkg directory (if something gets wrong, sometimes comit go git gelps)
|
44
|
-
* ``sudo rake install`` - installs gem to local system [^1]
|
76
|
+
1. Make changes
|
77
|
+
2. Test if all tests pass (run `bundle exec guard` to test automatically). If not go to 1.
|
78
|
+
3. Build and install locally using script `./reinstall_local_gem.sh` (see [details](reinstall_local_gem.sh))
|
45
79
|
4. Now can locally and manually use/test the gem. This should not be replacement for automated testing. If you make some changes, go to 1.
|
46
80
|
5. When happy, increment the version number and `git add .; git commit -am'commit message'; git push`
|
47
81
|
6. ``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.
|
@@ -52,8 +86,6 @@ gem alternativa to points 3-6
|
|
52
86
|
sudo gem install rspreadsheet-x.y.z.gem -/ which should be invoked from parent directory
|
53
87
|
gem push rspreadsheet-x.y.z.gem releases the gem, do not forgot to update version in rspreadsheet.gemspec before doing this
|
54
88
|
|
55
|
-
[^1]: 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``
|
56
|
-
|
57
89
|
### Naming conventions
|
58
90
|
|
59
91
|
* create_xxx - creates object and inserts it where necessary
|
data/GUIDE.md
CHANGED
@@ -1,3 +1,33 @@
|
|
1
|
+
## Guide to basic functionality
|
2
|
+
### Opening the file
|
3
|
+
|
4
|
+
You can open ODS file like this
|
5
|
+
````ruby
|
6
|
+
@workbook = Rspreadsheet.open('./test.ods')
|
7
|
+
````
|
8
|
+
and access its first sheet like this
|
9
|
+
````ruby
|
10
|
+
@sheet = @workbook.worksheets(1)
|
11
|
+
````
|
12
|
+
### Accessing cells
|
13
|
+
|
14
|
+
you can get and set contents of cells using "verbatim" syntax like
|
15
|
+
````ruby
|
16
|
+
@sheet.rows(5).cells(4).value
|
17
|
+
@sheet.rows(5).cells(4).value = 10
|
18
|
+
````
|
19
|
+
or using "brief" syntax like
|
20
|
+
````ruby
|
21
|
+
@sheet[5,4]
|
22
|
+
@sheet[5,4] = 10
|
23
|
+
````
|
24
|
+
|
25
|
+
You can mix these two at will, for example like this
|
26
|
+
````ruby
|
27
|
+
@row = @sheet.rows(5)
|
28
|
+
@row[4] = 10
|
29
|
+
````
|
30
|
+
|
1
31
|
## Examples
|
2
32
|
|
3
33
|
* [basic functionality](https://gist.github.com/gorn/42e33d086d9b4fda10ec)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# rspreadsheet
|
2
1
|
|
3
|
-
[![Build Status](https://api.travis-ci.org/gorn/rspreadsheet.svg?branch=master)](https://travis-ci.org/gorn/rspreadsheet) [![Coverage Status](https://coveralls.io/repos/gorn/rspreadsheet/badge.png)](https://coveralls.io/r/gorn/rspreadsheet)
|
2
|
+
[![Build Status](https://api.travis-ci.org/gorn/rspreadsheet.svg?branch=master)](https://travis-ci.org/gorn/rspreadsheet) [![Coverage Status](https://coveralls.io/repos/gorn/rspreadsheet/badge.png)](https://coveralls.io/r/gorn/rspreadsheet) [![User opinion wanted](https://badge.waffle.io/gorn/rspreadsheet.png?label=user opinion wanted&title=User opinion wanted)](https://waffle.io/gorn/rspreadsheet)
|
3
|
+
# rspreadsheet
|
4
4
|
|
5
5
|
Manipulating spreadsheets with Ruby. Read, **modify**, write or create new OpenDocument Spreadsheet files from ruby code.
|
6
6
|
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This module allows to define module configuration variables.
|
2
|
+
|
3
|
+
# see https://viget.com/extend/easy-gem-configuration-variables-with-defaults
|
4
|
+
|
5
|
+
module Configuration
|
6
|
+
def configuration
|
7
|
+
yield self
|
8
|
+
end
|
9
|
+
def define_setting(name, default = nil)
|
10
|
+
class_variable_set("@@#{name}", default)
|
11
|
+
define_class_method "#{name}=" do |value|
|
12
|
+
class_variable_set("@@#{name}", value)
|
13
|
+
end
|
14
|
+
define_class_method name do
|
15
|
+
class_variable_get("@@#{name}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
private
|
19
|
+
def define_class_method(name, &block)
|
20
|
+
(class << self; self; end).instance_eval do
|
21
|
+
define_method name, &block
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/rspreadsheet.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'rspreadsheet/version'
|
2
2
|
require 'rspreadsheet/workbook'
|
3
3
|
require 'rspreadsheet/worksheet'
|
4
|
-
require 'class_extensions'
|
4
|
+
require 'helpers/class_extensions'
|
5
|
+
require 'helpers/configuration'
|
5
6
|
|
6
7
|
module Rspreadsheet
|
8
|
+
extend Configuration
|
9
|
+
define_setting :raise_on_negative_coordinates, true
|
7
10
|
|
8
11
|
# makes creating new workbooks as easy as `Rspreadsheet.new` or `Rspreadsheet.open('filename.ods')
|
9
12
|
def self.new(filename=nil)
|
data/lib/rspreadsheet/version.rb
CHANGED
@@ -5,31 +5,6 @@ module Rspreadsheet
|
|
5
5
|
class Workbook
|
6
6
|
attr_reader :filename
|
7
7
|
attr_reader :xmlnode # debug
|
8
|
-
def initialize(afilename=nil)
|
9
|
-
@worksheets=[]
|
10
|
-
@filename = afilename
|
11
|
-
@content_xml = Zip::File.open(@filename || File.dirname(__FILE__)+'/empty_file_template.ods') do |zip|
|
12
|
-
LibXML::XML::Document.io zip.get_input_stream('content.xml')
|
13
|
-
end
|
14
|
-
@xmlnode = @content_xml.find_first('//office:spreadsheet')
|
15
|
-
@xmlnode.find('./table:table').each do |node|
|
16
|
-
create_worksheet_from_node(node)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
def save(new_filename=nil)
|
20
|
-
if @filename.nil? and new_filename.nil? then raise 'New file should be named on first save.' end
|
21
|
-
# if the filename has changed than first copy the original file to new location (or template if it is a new file)
|
22
|
-
if new_filename
|
23
|
-
FileUtils.cp(@filename || File.dirname(__FILE__)+'/empty_file_template.ods', new_filename)
|
24
|
-
@filename = new_filename
|
25
|
-
end
|
26
|
-
Zip::File.open(@filename) do |zip|
|
27
|
-
# it is easy, because @xmlnode in in sync with contents all the time
|
28
|
-
zip.get_output_stream('content.xml') do |f|
|
29
|
-
f.write @content_xml.to_s(:indent => false)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
8
|
def xmldoc; @xmlnode.doc end
|
34
9
|
|
35
10
|
#@!group Worskheets methods
|
@@ -38,7 +13,7 @@ class Workbook
|
|
38
13
|
register_worksheet(sheet)
|
39
14
|
return sheet
|
40
15
|
end
|
41
|
-
def create_worksheet(name = "
|
16
|
+
def create_worksheet(name = "Sheet#{worksheets_count+1}")
|
42
17
|
sheet = Worksheet.new(name)
|
43
18
|
register_worksheet(sheet)
|
44
19
|
return sheet
|
@@ -63,7 +38,43 @@ class Workbook
|
|
63
38
|
else raise 'method worksheets requires Integer index of the sheet or its String name'
|
64
39
|
end
|
65
40
|
end
|
41
|
+
alias :worksheet :worksheets
|
42
|
+
alias :sheet :worksheets
|
43
|
+
alias :sheets :worksheets
|
66
44
|
def [](index_or_name); self.worksheets(index_or_name) end
|
45
|
+
#@!group Loading and saving related methods
|
46
|
+
def initialize(afilename=nil)
|
47
|
+
@worksheets=[]
|
48
|
+
@filename = afilename
|
49
|
+
@content_xml = Zip::File.open(@filename || File.dirname(__FILE__)+'/empty_file_template.ods') do |zip|
|
50
|
+
LibXML::XML::Document.io zip.get_input_stream('content.xml')
|
51
|
+
end
|
52
|
+
@xmlnode = @content_xml.find_first('//office:spreadsheet')
|
53
|
+
@xmlnode.find('./table:table').each do |node|
|
54
|
+
create_worksheet_from_node(node)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
# @param [String] Optional new filename
|
58
|
+
# Saves the worksheet. Optionally you can provide new filename.
|
59
|
+
def save(new_filename=nil)
|
60
|
+
if @filename.nil? and new_filename.nil? then raise 'New file should be named on first save.' end
|
61
|
+
# if the filename has changed than first copy the original file to new location (or template if it is a new file)
|
62
|
+
if new_filename
|
63
|
+
FileUtils.cp(@filename || File.dirname(__FILE__)+'/empty_file_template.ods', new_filename)
|
64
|
+
@filename = new_filename
|
65
|
+
end
|
66
|
+
Zip::File.open(@filename) do |zip|
|
67
|
+
# it is easy, because @xmlnode in in sync with contents all the time
|
68
|
+
zip.get_output_stream('content.xml') do |f|
|
69
|
+
f.write @content_xml.to_s(:indent => false)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
# @return Mime of the file
|
74
|
+
def mime; 'application/vnd.oasis.opendocument.spreadsheet' end
|
75
|
+
# @return [String] Prefered file extension
|
76
|
+
def mime_preferred_extension; 'ods' end
|
77
|
+
alias :mime_default_extension :mime_preferred_extension
|
67
78
|
|
68
79
|
private
|
69
80
|
def register_worksheet(worksheet)
|
@@ -23,7 +23,7 @@ class Worksheet
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# name of the worksheet
|
26
|
-
# @returns [String]
|
26
|
+
# @returns [String] the name of the worksheet
|
27
27
|
def name; Tools.get_ns_attribute_value(@xmlnode,'table','name') end
|
28
28
|
def name=(value); Tools.set_ns_attribute(@xmlnode,'table','name', value) end
|
29
29
|
|
@@ -96,7 +96,8 @@ module XMLTiedArray
|
|
96
96
|
def subitem(aindex)
|
97
97
|
aindex = aindex.to_i
|
98
98
|
if aindex.to_i<=0
|
99
|
-
|
99
|
+
raise 'Item index should be greater then 0' if Rspreadsheet.raise_on_negative_coordinates
|
100
|
+
nil
|
100
101
|
else
|
101
102
|
@itemcache[aindex] ||= prepare_subitem(aindex)
|
102
103
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# remove previously build gems
|
4
|
+
rm -f pkg/rspreadsheet-0.*.gem
|
5
|
+
rm -f Gemfile.lock
|
6
|
+
|
7
|
+
# this is to update git index, because git lsfiles is used in .gemspec
|
8
|
+
git add .
|
9
|
+
|
10
|
+
# builds the gem to pkg directory and installs gem to local system
|
11
|
+
sudo rake install
|
12
|
+
|
13
|
+
# Note 1: If the last step fails with "mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h",
|
14
|
+
# you may want to ``sudo aptitude install ruby-dev``
|
15
|
+
|
data/spec/cell_spec.rb
CHANGED
@@ -52,10 +52,18 @@ describe Rspreadsheet::Cell do
|
|
52
52
|
@cell.range.should == (1..4)
|
53
53
|
@cell.mode.should == :repeated
|
54
54
|
end
|
55
|
-
it '
|
56
|
-
|
55
|
+
it 'returns nil on negative and zero cell indexes or raises exception depending on configuration' do
|
56
|
+
pom = Rspreadsheet.raise_on_negative_coordinates
|
57
|
+
# default is to raise error
|
58
|
+
expect {@sheet2.cells(0,5) }.to raise_error
|
59
|
+
|
60
|
+
# return nil if configured to do so
|
61
|
+
Rspreadsheet.raise_on_negative_coordinates = false
|
62
|
+
@sheet2.cells(0,5).should be_nil
|
57
63
|
@sheet2.cells(2,-5).should be(nil)
|
58
64
|
@sheet2.cells(-2,-5).should be(nil)
|
65
|
+
|
66
|
+
Rspreadsheet.raise_on_negative_coordinates = pom # reset the setting back
|
59
67
|
end
|
60
68
|
it 'has nonempty parents' do
|
61
69
|
@cell = @sheet2.cells(13,5)
|
data/spec/row_spec.rb
CHANGED
@@ -103,9 +103,18 @@ describe Rspreadsheet::Row do
|
|
103
103
|
@sheet1.rows(17).style_name = 'newstylename2'
|
104
104
|
@sheet1.rows(17).xmlnode.attributes.get_attribute_ns(table_ns_href,'style-name').value.should == 'newstylename2'
|
105
105
|
end
|
106
|
-
it '
|
106
|
+
it 'returns nil on negative and zero row indexes or raises exception depending on configuration' do
|
107
|
+
pom = Rspreadsheet.raise_on_negative_coordinates
|
108
|
+
# default is to raise exception
|
109
|
+
expect { @sheet1.rows(0) }.to raise_error
|
110
|
+
expect { @sheet1.rows(-78) }.to raise_error
|
111
|
+
|
112
|
+
# if configured, it needs to ignore it (and return nil)
|
113
|
+
Rspreadsheet.raise_on_negative_coordinates = false
|
107
114
|
@sheet1.rows(0).should be_nil
|
108
115
|
@sheet1.rows(-78).should be_nil
|
116
|
+
|
117
|
+
Rspreadsheet.raise_on_negative_coordinates = pom # reset the setting back
|
109
118
|
end
|
110
119
|
it 'has correct rowindex' do
|
111
120
|
@sheet1.rows(5).detach
|
@@ -249,8 +258,3 @@ describe Rspreadsheet::Row do
|
|
249
258
|
end
|
250
259
|
|
251
260
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
data/spec/workbook_spec.rb
CHANGED
@@ -47,4 +47,13 @@ describe Rspreadsheet::Workbook do
|
|
47
47
|
book['test'].should be book.worksheets(1)
|
48
48
|
book[1].should be book.worksheets(1)
|
49
49
|
end
|
50
|
+
it 'can access sheet with alternative syntax and always returns the same object' do
|
51
|
+
book = Rspreadsheet::Workbook.new
|
52
|
+
book.create_worksheet('test')
|
53
|
+
book.create_worksheet('test2')
|
54
|
+
sheet = book.worksheets(1)
|
55
|
+
book.worksheet(1).should == sheet
|
56
|
+
book.sheet(1).should == sheet
|
57
|
+
book.sheets(2).should_not == sheet
|
58
|
+
end
|
50
59
|
end
|
data/spec/worksheet_spec.rb
CHANGED
@@ -15,62 +15,81 @@ describe Rspreadsheet::Worksheet do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe Rspreadsheet::Worksheet
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
18
|
+
describe Rspreadsheet::Worksheet do
|
19
|
+
describe "newly created" do
|
20
|
+
before do
|
21
|
+
@book = Rspreadsheet.new
|
22
|
+
@sheet = @book.create_worksheet
|
23
|
+
end
|
24
|
+
it 'has correctly namespaced xmlnode' do
|
25
|
+
@xmlnode = @sheet.xmlnode
|
26
|
+
@xmlnode.namespaces.to_a.size.should >5
|
27
|
+
@xmlnode.namespaces.find_by_prefix('office').should_not be_nil
|
28
|
+
@xmlnode.namespaces.find_by_prefix('table').should_not be_nil
|
29
|
+
@xmlnode.namespaces.namespace.should_not be_nil
|
30
|
+
@xmlnode.namespaces.namespace.prefix.should == 'table'
|
31
|
+
end
|
32
|
+
it 'has correct name' do
|
33
|
+
@sheet2 = @book.create_worksheet('test')
|
34
|
+
@sheet2.name.should eq 'test'
|
35
|
+
@sheet3 = @book.create_worksheet
|
36
|
+
@sheet3.name.should eq 'Sheet3'
|
37
|
+
end
|
38
|
+
it 'remembers the value stored to A1 cell' do
|
39
|
+
@sheet[1,1].should == nil
|
40
|
+
@sheet[1,1] = 'test text'
|
41
|
+
@sheet[1,1].class.should == String
|
42
|
+
@sheet[1,1].should == 'test text'
|
43
|
+
end
|
44
|
+
it 'value stored to A1 is accesible using different syntax' do
|
45
|
+
@sheet[2,2] = 'test text'
|
46
|
+
@sheet[2,2].should == 'test text'
|
47
|
+
@sheet.B2.should == 'test text'
|
48
|
+
@sheet['B2'].should == 'test text'
|
49
|
+
@sheet['2','2'].should == 'test text'
|
50
|
+
@sheet['2','B'].should == 'test text'
|
51
|
+
@sheet[2,'B'].should == 'test text'
|
52
|
+
@sheet['B',2].should == 'test text'
|
53
|
+
@sheet['B','2'].should == 'test text'
|
54
|
+
|
55
|
+
@sheet.cells(2,2).value.should == 'test text'
|
56
|
+
@sheet.cells('B2').value.should == 'test text'
|
57
|
+
@sheet.cells('B','2').value.should == 'test text'
|
58
|
+
@sheet.cells(2,'B').value.should == 'test text'
|
59
|
+
end
|
60
|
+
it 'makes Cell object accessible' do
|
61
|
+
@sheet.cells(1,1).value = 'test text'
|
62
|
+
@sheet.cells(1,1).class.should == Rspreadsheet::Cell
|
63
|
+
end
|
64
|
+
it 'has name, which can be changed and is remembered' do
|
65
|
+
@sheet.name.should_not be(nil) # it should have some default name
|
66
|
+
@sheet.name = 'Icecream'
|
67
|
+
@sheet.name.should == 'Icecream'
|
68
|
+
@sheet.name = 'Cofee'
|
69
|
+
@sheet.name.should == 'Cofee'
|
70
|
+
end
|
71
|
+
it 'out of range indexes return nil value or raise if configured to do so' do
|
72
|
+
@sheet[999,999].should == nil
|
73
|
+
|
74
|
+
pom = Rspreadsheet.raise_on_negative_coordinates
|
75
|
+
expect { @sheet[-1,-1] }.to raise_error # default is to raise error
|
76
|
+
expect { @sheet[0,0] }.to raise_error
|
77
|
+
expect { @sheet[-2,-5] }.to raise_error
|
78
|
+
|
79
|
+
Rspreadsheet.raise_on_negative_coordinates = false
|
80
|
+
@sheet[-1,-1].should be_nil # return nil if configured to do so
|
81
|
+
@sheet[0,0].should be_nil
|
82
|
+
@sheet[-2,-5].should be_nil
|
83
|
+
|
84
|
+
Rspreadsheet.raise_on_negative_coordinates = pom # reset the setting back
|
85
|
+
end
|
86
|
+
it 'returns nil with negative index or raise if configured to do so' do
|
87
|
+
pom = Rspreadsheet.raise_on_negative_coordinates
|
88
|
+
expect { @sheet.rows(-1) }.to raise_error # default is to raise error
|
89
|
+
|
90
|
+
Rspreadsheet.raise_on_negative_coordinates = false
|
91
|
+
@sheet.rows(-1).should == nil # return nil if configured to do so
|
92
|
+
Rspreadsheet.raise_on_negative_coordinates = pom # reset the setting back
|
93
|
+
end
|
75
94
|
end
|
76
|
-
end
|
95
|
+
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.
|
4
|
+
version: 0.2.11
|
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: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libxml-ruby
|
@@ -175,7 +175,8 @@ files:
|
|
175
175
|
- README.md
|
176
176
|
- Rakefile
|
177
177
|
- investigate.rb
|
178
|
-
- lib/class_extensions.rb
|
178
|
+
- lib/helpers/class_extensions.rb
|
179
|
+
- lib/helpers/configuration.rb
|
179
180
|
- lib/rspreadsheet.rb
|
180
181
|
- lib/rspreadsheet/cell.rb
|
181
182
|
- lib/rspreadsheet/empty_file_template.ods
|
@@ -185,8 +186,7 @@ files:
|
|
185
186
|
- lib/rspreadsheet/workbook.rb
|
186
187
|
- lib/rspreadsheet/worksheet.rb
|
187
188
|
- lib/rspreadsheet/xml_tied.rb
|
188
|
-
-
|
189
|
-
- reinstall2.sh
|
189
|
+
- reinstall_local_gem.sh
|
190
190
|
- rspreadsheet.gemspec
|
191
191
|
- spec/cell_spec.rb
|
192
192
|
- spec/row_spec.rb
|
data/reinstall.sh
DELETED