tablespoon 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,17 @@
1
1
  Copyright (c) 2013 Matt Ericson
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
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
 
@@ -1,16 +1,41 @@
1
1
  = tablespoon
2
2
 
3
- Description goes here.
3
+ Access Google Spreadsheets in a vaguely record-like way.
4
4
 
5
- == Contributing to tablespoon
5
+ == Requirements
6
6
 
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
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
1
+ 0.0.2
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "tablespoon"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matthew Ericson"]
@@ -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
- puts "hi"
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 1
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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew Ericson