tablespoon 0.0.1 → 0.0.2
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/LICENSE.txt +11 -7
- data/README.rdoc +34 -9
- data/VERSION +1 -1
- data/lib/tablespoon.rb +10 -6
- data/tablespoon.gemspec +1 -1
- data/test/test.rb +2 -3
- metadata +3 -3
data/LICENSE.txt
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
Copyright (c) 2013 Matt Ericson
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
4
|
+
it under the terms of the GNU General Public License as published by
|
5
|
+
the Free Software Foundation, either version 3 of the License, or (at
|
6
|
+
your option) any later version.
|
10
7
|
|
8
|
+
This program is distributed in the hope that it will be useful, but
|
9
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
General Public License for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU General Public License
|
14
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
11
15
|
The above copyright notice and this permission notice shall be
|
12
16
|
included in all copies or substantial portions of the Software.
|
13
17
|
|
data/README.rdoc
CHANGED
@@ -1,16 +1,41 @@
|
|
1
1
|
= tablespoon
|
2
2
|
|
3
|
-
|
3
|
+
Access Google Spreadsheets in a vaguely record-like way.
|
4
4
|
|
5
|
-
==
|
5
|
+
== Requirements
|
6
6
|
|
7
|
-
*
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
* Google Spreadsheet that is organized like a database table. Fieldnames in the first row, records in the rest of the rows.
|
8
|
+
|
9
|
+
== Installation
|
10
|
+
|
11
|
+
sudo gem install tablespoon
|
12
|
+
|
13
|
+
== How to Use
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
require 'tablespoon'
|
17
|
+
|
18
|
+
Connect to a Google doc
|
19
|
+
|
20
|
+
doc = Tablespoon::Doc.new( "0ArhhvPZdTe-WdGpZQ3pEY1hDcEUxWmxwNnJEQ3g4aVE",
|
21
|
+
:username => google_username, :password => google_password )
|
22
|
+
|
23
|
+
Get a worksheet either by name or by id. (Coming soon: Optionally, declare an id field so you can find rows by id later.)
|
24
|
+
|
25
|
+
rows = doc.get_table 'Sheet1', :id_field => 'last-name'
|
26
|
+
|
27
|
+
Loop thru rows and retrieve data
|
28
|
+
|
29
|
+
rows.each do |r|
|
30
|
+
puts r['full-name']
|
31
|
+
end
|
32
|
+
|
33
|
+
Modify fields and save data back to the spreadsheet.
|
34
|
+
|
35
|
+
rows.each do |r|
|
36
|
+
r['full-name'] = r['full-name'].upcase
|
37
|
+
end
|
38
|
+
|
14
39
|
|
15
40
|
== Copyright
|
16
41
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/tablespoon.rb
CHANGED
@@ -8,7 +8,6 @@ module Tablespoon
|
|
8
8
|
attr_reader :session, :doc
|
9
9
|
|
10
10
|
def initialize( key, opts = {} )
|
11
|
-
pp opts
|
12
11
|
if opts[:username] && opts [:password]
|
13
12
|
@session = GoogleDrive.login( opts[:username], opts[:password] )
|
14
13
|
@doc = session.spreadsheet_by_key( key )
|
@@ -43,8 +42,6 @@ module Tablespoon
|
|
43
42
|
|
44
43
|
|
45
44
|
build_column_map
|
46
|
-
pp @column_map
|
47
|
-
pp @field_map
|
48
45
|
|
49
46
|
# build data array
|
50
47
|
|
@@ -58,12 +55,12 @@ module Tablespoon
|
|
58
55
|
|
59
56
|
for col in 1..@ws.num_cols
|
60
57
|
data[ column_map[col] ] = @ws[ row, col ]
|
61
|
-
|
58
|
+
|
62
59
|
if column_map[col] == @id_field
|
63
60
|
r.id = @ws[ row, col ]
|
64
61
|
end
|
65
62
|
end
|
66
|
-
|
63
|
+
|
67
64
|
r.data=data
|
68
65
|
|
69
66
|
@rows << r
|
@@ -76,6 +73,14 @@ module Tablespoon
|
|
76
73
|
return @rows[i]
|
77
74
|
end
|
78
75
|
|
76
|
+
def length
|
77
|
+
return @rows.length
|
78
|
+
end
|
79
|
+
|
80
|
+
def last
|
81
|
+
return @rows.last
|
82
|
+
end
|
83
|
+
|
79
84
|
def each
|
80
85
|
@rows.each { |i| yield i }
|
81
86
|
end
|
@@ -110,7 +115,6 @@ module Tablespoon
|
|
110
115
|
end
|
111
116
|
|
112
117
|
def []= (field,value)
|
113
|
-
puts "Setting {field} to {value]"
|
114
118
|
|
115
119
|
## get the column number where we think it is
|
116
120
|
## if it's not there, rebuild the field map
|
data/tablespoon.gemspec
CHANGED
data/test/test.rb
CHANGED
@@ -15,9 +15,8 @@ doc = Tablespoon::Doc.new( "0ArhhvPZdTe-WdGpZQ3pEY1hDcEUxWmxwNnJEQ3g4aVE",
|
|
15
15
|
justices = doc.get_table 'Sheet1', :id_field => 'last-name'
|
16
16
|
|
17
17
|
justices.each do |r|
|
18
|
-
|
19
|
-
r['full-name'] = r['full-name'].downcase
|
18
|
+
r['full-name'] = r['full-name'].upcase
|
20
19
|
puts r['some_value'] = 'monkeys'
|
21
|
-
sleep
|
20
|
+
sleep 2
|
22
21
|
end
|
23
22
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablespoon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthew Ericson
|