rspreadsheet 0.2.5 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82068f98220c39b9d05ca4a5cd3bfa2e1eb55eb4
4
- data.tar.gz: 95410381c26b1ca2527188b7165ac52ec7277dec
3
+ metadata.gz: f9603ed2713de6f87efb309a9cd9f36388001731
4
+ data.tar.gz: baa73509ae8527b93fa5dc19596a244ed21f5171
5
5
  SHA512:
6
- metadata.gz: 7e2cc1abbb8281f7e8931453f1e404170faea8254f60bb8b2a7ad677c56cb1abcd0a94906bd8eeb226dcd2dfe720de1d24b1c57c97004e77f8af956d01afa498
7
- data.tar.gz: 204a41ca91da4f85fd478ce926188ebf41abd82fe890d0b4fc23f57e78a73a28d7695a03b17dceae957b249029b7381a4f8608094eb4ebeaafde63429b3cb736
6
+ metadata.gz: 691688a99bd3900f791502e2efd9b74b5fb745f1044ef349885fec3323ff6e95fc074fcd65c5c55a2b972f50a49715d58381e5b7b00f65c662dc4f5293378b90
7
+ data.tar.gz: 1a57249cbdceb90ff94a8544a7f370c89124008d6c33dc9777a2aeae83e3fb6e6f4b67bb7380df27496726170d0a84be36feb51083d9fffda525ba34c9ea10d5
data/.gitignore CHANGED
@@ -10,6 +10,7 @@
10
10
  /test/version_tmp/
11
11
  /tmp/
12
12
  lib/bundler/man
13
+ .kateproject.d
13
14
 
14
15
  ## Specific to RubyMotion:
15
16
  .dat*
data/DEVEL_BLOG.md CHANGED
@@ -37,7 +37,7 @@ Guiding ideas
37
37
  1. make changes
38
38
  2. test if all tests pass (run `bundle exex guard` to test automatically). If not go to 1
39
39
  3. build and install locally
40
- * ``rake build`` - builds the gem to pkg directory.
40
+ * ``rake build`` - builds the gem to pkg directory (if something gets wrong, sometimes comit go git gelps)
41
41
  * ``sudo rake install`` - installs gem to local system [^1]
42
42
  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.
43
43
  5. When happy, increment the version number and `git add .; git commit -am'commit message'; git push`
data/GUIDE.md CHANGED
@@ -1,50 +1,8 @@
1
- ## Examples of advanced syntax
1
+ ## Examples
2
2
 
3
- Examples of more advanced syntax follows
3
+ * [basic functionality](https://gist.github.com/gorn/42e33d086d9b4fda10ec)
4
+ * [extended examples](https://gist.github.com/gorn/b432e6a69e82628349e6) of lots of alternative syntax
4
5
 
5
- ```ruby
6
- require 'rspreadsheet'
7
-
8
- book = Rspreadsheet.new
9
- sheet = book.create_worksheet 'Top icecreams'
10
-
11
- sheet[1,1] = 'My top 5'
12
- p sheet[1,1].class # => String
13
- p sheet[1,1] # => "My top 5"
14
-
15
- # These are all the same values - alternative syntax
16
- p sheet.rows(1).cells(0).value
17
- p sheet.cells(1,1).value
18
- p sheet.A1
19
- p sheet[1,1]
20
-
21
- # How to inspect/manipulate the Cell object
22
- sheet.cells(1,1) # => Rspreadsheet::Cell
23
- sheet.cells(1,1).format
24
- sheet.cells(1,1).format.size = 15
25
- sheet.cells(1,1).format.weight = bold
26
- p sheet.cells(1,1).format.bold? # => true
27
-
28
- # There are the same assigmenents
29
- sheet.A1 = value
30
- sheet[1,1]= value
31
- sheet.cells(1,1).value = value
32
-
33
- p sheet.A1.class # => Rspreadsheet::Cell
34
-
35
- # relative cells
36
- sheet.cells(4,7).relative(-1,0) # => cell 3,7
37
-
38
- # build the top five list
39
- (1..5).each { |i| sheet[i,1] = i }
40
- sheet.columns(1).format.bold = true
41
- sheet.cells[2,1..5] = ['Vanilla', 'Pistacia', 'Chocolate', 'Annanas', 'Strawbery']
42
-
43
- sheet.columns(1).cells(1).format.color = :red
44
-
45
- book.save
46
-
47
- ```
48
6
  ## Conventions
49
7
  * **all indexes are 1-based**. This applies to rows, cells cordinates, and all array like structures like list od worksheets etc. Spreadsheet world is 1-based, ruby is 0-based do I had to make a decision. I intend to make an global option for this, but in early stage I need to keep things simple.
50
8
  * with numeric coordinates row always comes before col as in (row,col)
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # rspreadsheet
2
2
 
3
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)
4
-
4
+
5
5
  Manipulating spreadsheets with Ruby. Read, modify, write or create new OpenDocument Spreadsheet files from ruby code.
6
6
 
7
7
  ## Contibutions, ideas and wishes welcomed
@@ -14,8 +14,8 @@ Alhought this gem is still in alpha stage I use in my project it and it works fi
14
14
 
15
15
  ```ruby
16
16
  require 'rspreadsheet'
17
- book = Rspreadsheet.open('spreadsheet.ods')
18
- sheet = book.worksheets[1]
17
+ book = Rspreadsheet.open('./test.ods')
18
+ sheet = book.worksheets(1)
19
19
 
20
20
 
21
21
  # get value of a cell B5 (there are more ways to do this)
@@ -30,28 +30,31 @@ sheet.cells(5,2).value = 1.78
30
30
 
31
31
  # working with cell format
32
32
  sheet.cells(5,2).format.bold = true
33
- sheet.cells(5,2).format.background = '#FF0000'
33
+ sheet.cells(5,2).format.background_color = '#FF0000'
34
34
 
35
35
  # calculating sum of cells in row
36
36
  sheet.rows(5).cellvalues.sum
37
- sheet.rows(5).cells.sum{ |cell| cell.value }
37
+ sheet.rows(5).cells.sum{ |cell| cell.value.to_f }
38
38
 
39
39
  # iterating over list of people and displaying the data
40
40
 
41
41
  total = 0
42
42
  sheet.rows.each do |row|
43
43
  puts "Sponsor #{row[1]} with email #{row[2]} has donated #{row[3]} USD."
44
- total += row[3]
44
+ total += row[3].to_f
45
45
  end
46
46
  puts "Totally fundraised #{total} USD"
47
47
 
48
48
  # saving file
49
49
  book.save
50
50
  book.save('different_filename.ods')
51
-
52
51
  ```
53
52
 
54
- This is the basic functionality. However rspreadsheet should allows lots of alternative syntax, like described in [GUIDE.md](GUIDE.md)
53
+ This is also pubished as Gist **where you can leave you comments and suggestions**:
54
+
55
+ * [basic functionality](https://gist.github.com/gorn/42e33d086d9b4fda10ec)
56
+ * [extended examples](https://gist.github.com/gorn/b432e6a69e82628349e6) of lots of alternative syntax
57
+ * [GUIDE.md](GUIDE.md) some other notes
55
58
 
56
59
  ## Installation
57
60
 
@@ -43,7 +43,7 @@ class Array
43
43
  if block_given?
44
44
  map(&block).sum(identity)
45
45
  else
46
- inject { |sum, element| sum + element } || identity
46
+ inject(0){ |sum, element| sum.to_f + element.to_f } || identity
47
47
  end
48
48
  end
49
49
  end
@@ -191,6 +191,7 @@ class CellFormat
191
191
 
192
192
  # text style attribute readers
193
193
  def bold; get_text_style_node_attribute('font-weight') == 'bold' end
194
+ alias :bold? :bold
194
195
  def italic; get_text_style_node_attribute('font-style') == 'italic' end
195
196
  def color; get_text_style_node_attribute('color') end
196
197
  def font_size; get_text_style_node_attribute('font-size') end
@@ -252,7 +253,7 @@ class CellFormat
252
253
  last = cellnode.doc.root.find('./office:automatic-styles/style:style').
253
254
  collect {|node| node['name']}.
254
255
  collect{ |name| /^ce(\d*)$/.match(name); $1.andand.to_i}.
255
- compact.max
256
+ compact.max || 0
256
257
  "ce#{last+1}"
257
258
  end
258
259
  def automatic_styles_node; cellnode.doc.root.find("./office:automatic-styles").first end
@@ -1,3 +1,3 @@
1
1
  module Rspreadsheet
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.7"
3
3
  end
@@ -8,7 +8,7 @@ class Workbook
8
8
  def initialize(afilename=nil)
9
9
  @worksheets=[]
10
10
  @filename = afilename
11
- @content_xml = Zip::File.open(@filename || './lib/rspreadsheet/empty_file_template.ods') do |zip|
11
+ @content_xml = Zip::File.open(@filename || File.dirname(__FILE__)+'/empty_file_template.ods') do |zip|
12
12
  LibXML::XML::Document.io zip.get_input_stream('content.xml')
13
13
  end
14
14
  @xmlnode = @content_xml.find_first('//office:spreadsheet')
@@ -20,7 +20,7 @@ class Workbook
20
20
  if @filename.nil? and new_filename.nil? then raise 'New file should be named on first save.' end
21
21
  # if the filename has changed than first copy the original file to new location (or template if it is a new file)
22
22
  if new_filename
23
- FileUtils.cp(@filename || './lib/rspreadsheet/empty_file_template.ods', new_filename)
23
+ FileUtils.cp(@filename || File.dirname(__FILE__)+'/empty_file_template.ods', new_filename)
24
24
  @filename = new_filename
25
25
  end
26
26
  Zip::File.open(@filename) do |zip|
data/spec/cell_spec.rb CHANGED
@@ -184,8 +184,9 @@ describe Rspreadsheet::Cell do
184
184
  # after fresh create
185
185
  @cell.xmlnode.attributes['style-name'].should_not be_nil
186
186
  end
187
- it 'can set formats of the cells' do
188
- @cell = @sheet2.cells(1,1)
187
+ it 'can set formats of the cells in new file' do
188
+ @cell = @sheet1.cells(1,1)
189
+ @cell.value = '1'
189
190
  # bold
190
191
  @cell.format.bold.should be_falsey
191
192
  @cell.format.bold = true
@@ -98,6 +98,51 @@ describe Rspreadsheet do
98
98
  end
99
99
  total.should eq 55
100
100
  end
101
+ it 'examples from advanced syntax GUIDE are working' do
102
+ def p(*par); end # supress p in the example
103
+ expect do
104
+ book = Rspreadsheet::Workbook.new
105
+ sheet = book.create_worksheet 'Top icecreams'
106
+
107
+ sheet[1,1] = 'My top 5'
108
+ p sheet[1,1].class # => String
109
+ p sheet[1,1] # => "My top 5"
110
+
111
+ # These are all the same values - alternative syntax
112
+ p sheet.rows(1).cells(1).value
113
+ p sheet.cells(1,1).value
114
+ p sheet.A1
115
+ p sheet[1,1]
116
+ p sheet['A1']
117
+ p sheet.cells('A1').value
118
+
119
+ # How to inspect/manipulate the Cell object
120
+ sheet.cells(1,1) # => Rspreadsheet::Cell
121
+ sheet.cells(1,1).format
122
+ sheet.cells(1,1).format.font_size = '15pt'
123
+ sheet.cells(1,1).format.bold = true
124
+ p sheet.cells(1,1).format.bold? # => true
125
+
126
+ # There are the same assigmenents
127
+ value = 1.234
128
+ sheet.A1 = value
129
+ sheet[1,1]= value
130
+ sheet.cells(1,1).value = value
131
+
132
+ p sheet.A1.class # => Rspreadsheet::Cell
133
+
134
+ # relative cells
135
+ sheet.cells(4,7).relative(-1,0) # => cell 3,7
136
+
137
+ # build the top five list (these features are not implemented yet)
138
+ # (1..5).each { |i| sheet[i,1] = i }
139
+ # sheet.columns(1).format.bold = true
140
+ # sheet.cells[2,1..5] = ['Vanilla', 'Pistacia', 'Chocolate', 'Annanas', 'Strawbery']
141
+ # sheet.columns(1).cells(1).format.color = :red
142
+
143
+ book.save('testfile.ods')
144
+ end.not_to raise_error
145
+ end
101
146
  end
102
147
 
103
148
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspreadsheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub A.Těšínský
@@ -163,7 +163,6 @@ files:
163
163
  - ".directory"
164
164
  - ".gitignore"
165
165
  - ".kateproject"
166
- - ".kateproject.d/notes.txt"
167
166
  - ".travis.yml"
168
167
  - ".yardopts"
169
168
  - CHANGELOG.md
@@ -180,7 +179,6 @@ files:
180
179
  - lib/rspreadsheet.rb
181
180
  - lib/rspreadsheet/cell.rb
182
181
  - lib/rspreadsheet/empty_file_template.ods
183
- - lib/rspreadsheet/empty_file_template.old.ods
184
182
  - lib/rspreadsheet/row.rb
185
183
  - lib/rspreadsheet/tools.rb
186
184
  - lib/rspreadsheet/version.rb
File without changes