tablespoon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "google_drive", ">=0.3.0"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", "~> 1.1.0"
13
+ gem "jeweler", "~> 1.8.4"
14
+ gem "rcov", ">= 0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ faraday (0.8.1)
5
+ multipart-post (~> 1.1)
6
+ git (1.2.5)
7
+ google_drive (0.3.1)
8
+ nokogiri (>= 1.4.4, != 1.5.2, != 1.5.1)
9
+ oauth (>= 0.3.6)
10
+ oauth2 (>= 0.5.0)
11
+ httpauth (0.1)
12
+ jeweler (1.8.4)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ rdoc
17
+ json (1.7.6)
18
+ jwt (0.1.4)
19
+ json (>= 1.2.4)
20
+ multi_json (1.5.0)
21
+ multipart-post (1.1.5)
22
+ nokogiri (1.5.5)
23
+ oauth (0.4.6)
24
+ oauth2 (0.8.0)
25
+ faraday (~> 0.8)
26
+ httpauth (~> 0.1)
27
+ jwt (~> 0.1.4)
28
+ multi_json (~> 1.0)
29
+ rack (~> 1.2)
30
+ rack (1.4.4)
31
+ rake (10.0.3)
32
+ rcov (1.0.0)
33
+ rdoc (3.12)
34
+ json (~> 1.4)
35
+ shoulda (3.0.1)
36
+ shoulda-context (~> 1.0.0)
37
+ shoulda-matchers (~> 1.0.0)
38
+ shoulda-context (1.0.0)
39
+ shoulda-matchers (1.0.0)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.1.0)
46
+ google_drive (>= 0.3.0)
47
+ jeweler (~> 1.8.4)
48
+ rcov
49
+ rdoc (~> 3.12)
50
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Matt Ericson
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:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = tablespoon
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to tablespoon
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.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Matt Ericson. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "tablespoon"
18
+ gem.homepage = "http://github.com/mericson/tablespoon"
19
+ gem.license = "GPL"
20
+ gem.summary = %Q{Read and write Google Spreadsheets like records}
21
+ gem.description = %Q{Read and write Google Spreadsheets like records}
22
+ gem.email = "mericson@ericson.net"
23
+ gem.authors = ["Matthew Ericson"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "tablespoon #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/tablespoon.rb ADDED
@@ -0,0 +1,176 @@
1
+ require 'google_drive'
2
+ require 'pp'
3
+
4
+ module Tablespoon
5
+
6
+ class Doc
7
+
8
+ attr_reader :session, :doc
9
+
10
+ def initialize( key, opts = {} )
11
+ pp opts
12
+ if opts[:username] && opts [:password]
13
+ @session = GoogleDrive.login( opts[:username], opts[:password] )
14
+ @doc = session.spreadsheet_by_key( key )
15
+ else
16
+ raise "No username and password"
17
+ end
18
+ end
19
+
20
+ def get_table( x, opts = {} )
21
+ if x.class == String
22
+ return Table.new @doc.worksheet_by_title( x ), opts
23
+ else
24
+ return Table.new @doc.worksheets[x], opts
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ class Table
32
+
33
+ include Enumerable
34
+
35
+ attr_accessor :doc, :ws, :column_map, :field_map, :id_field, :include_blank_rows
36
+
37
+ def initialize( ws, opts = {} )
38
+ @ws = ws
39
+
40
+ # handle some options
41
+ @id_field = opts[:id_field]
42
+ @include_blank_row = opts[:include_blank_rows] || true
43
+
44
+
45
+ build_column_map
46
+ pp @column_map
47
+ pp @field_map
48
+
49
+ # build data array
50
+
51
+ @rows = []
52
+
53
+ for row in 2..@ws.num_rows
54
+ r = Record.new self
55
+ r.row_num = row
56
+
57
+ data = {}
58
+
59
+ for col in 1..@ws.num_cols
60
+ data[ column_map[col] ] = @ws[ row, col ]
61
+
62
+ if column_map[col] == @id_field
63
+ r.id = @ws[ row, col ]
64
+ end
65
+ end
66
+
67
+ r.data=data
68
+
69
+ @rows << r
70
+
71
+ end
72
+
73
+ end
74
+
75
+ def []
76
+ return @rows[i]
77
+ end
78
+
79
+ def each
80
+ @rows.each { |i| yield i }
81
+ end
82
+
83
+ def find
84
+ end
85
+
86
+ def find_by_id
87
+ end
88
+
89
+ def save
90
+ @ws.save
91
+ end
92
+
93
+ def build_column_map
94
+ @column_map = {}
95
+ for col in 1..@ws.num_cols
96
+ @column_map[ col ] = @ws[ 1,col ]
97
+ end
98
+
99
+ @field_map = column_map.invert
100
+ end
101
+
102
+ end
103
+
104
+ class Record
105
+
106
+ attr_accessor :row_num, :id, :data
107
+
108
+ def [] (field)
109
+ return @data[field]
110
+ end
111
+
112
+ def []= (field,value)
113
+ puts "Setting {field} to {value]"
114
+
115
+ ## get the column number where we think it is
116
+ ## if it's not there, rebuild the field map
117
+ ## and try again
118
+
119
+ col_num = get_col_num( field )
120
+ row_num = @row_num
121
+
122
+ ## if we have an id field defined, check to make
123
+ ## sure the row we are updating matches
124
+
125
+ if @id_field
126
+ id_col_num = get_col_num( @id_field )
127
+ if @ws[row_num, id_col_num] == id
128
+ @ws[row_num, col_num] = value
129
+ else
130
+ raise "Row has moved"
131
+ end
132
+
133
+ else
134
+ @ws[row_num, col_num] = value
135
+ end
136
+
137
+ @ws.save
138
+
139
+ end
140
+
141
+ def get_col_num( field )
142
+
143
+ col_num = @field_map[field]
144
+
145
+ if ! @ws[1,col_num] == field
146
+ @table.build_column_map
147
+ col_num = @field_map[field]
148
+
149
+ if ! @ws[1,col_num] == field
150
+ raise "Unable to find field #{field}"
151
+ end
152
+ end
153
+
154
+ return col_num
155
+
156
+ end
157
+
158
+ def initialize( table )
159
+
160
+ @table = table
161
+
162
+ @field_map = table.field_map
163
+ @ws = table.ws
164
+ @id_field = table.id_field
165
+
166
+ @data = {}
167
+
168
+ end
169
+
170
+ def to_s
171
+ return "Row #{@row_num} Id #{@id} " + @data.keys.collect { |a| "#{a}: #{@data[a]}" }.join ( ' - ' )
172
+ end
173
+
174
+ end
175
+
176
+ end
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "tablespoon"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matthew Ericson"]
12
+ s.date = "2013-01-25"
13
+ s.description = "Read and write Google Spreadsheets like records"
14
+ s.email = "mericson@ericson.net"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/tablespoon.rb",
28
+ "tablespoon.gemspec",
29
+ "test/helper.rb",
30
+ "test/test.rb",
31
+ "test/test_tablespoon.rb"
32
+ ]
33
+ s.homepage = "http://github.com/mericson/tablespoon"
34
+ s.licenses = ["GPL"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.24"
37
+ s.summary = "Read and write Google Spreadsheets like records"
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<google_drive>, [">= 0.3.0"])
44
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
48
+ s.add_development_dependency(%q<rcov>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<google_drive>, [">= 0.3.0"])
51
+ s.add_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<google_drive>, [">= 0.3.0"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ end
65
+ end
66
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'tablespoon'
16
+
17
+ class Test::Unit::TestCase
18
+ end
data/test/test.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'pp'
3
+ require '../lib/tablespoon.rb'
4
+
5
+ google_username = ENV['GOOGLE_USERNAME']
6
+ google_password = ENV['GOOGLE_PASSWORD']
7
+
8
+ puts "Looging into Google with "
9
+ puts "#{google_username}"
10
+ puts "#{google_password}"
11
+
12
+ doc = Tablespoon::Doc.new( "0ArhhvPZdTe-WdGpZQ3pEY1hDcEUxWmxwNnJEQ3g4aVE",
13
+ :username => google_username, :password => google_password )
14
+
15
+ justices = doc.get_table 'Sheet1', :id_field => 'last-name'
16
+
17
+ justices.each do |r|
18
+ puts "hi"
19
+ r['full-name'] = r['full-name'].downcase
20
+ puts r['some_value'] = 'monkeys'
21
+ sleep 1
22
+ end
23
+
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestTablespoon < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tablespoon
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Matthew Ericson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-25 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 19
27
+ segments:
28
+ - 0
29
+ - 3
30
+ - 0
31
+ version: 0.3.0
32
+ version_requirements: *id001
33
+ name: google_drive
34
+ prerelease: false
35
+ type: :runtime
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ version_requirements: *id002
47
+ name: shoulda
48
+ prerelease: false
49
+ type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 31
57
+ segments:
58
+ - 3
59
+ - 12
60
+ version: "3.12"
61
+ version_requirements: *id003
62
+ name: rdoc
63
+ prerelease: false
64
+ type: :development
65
+ - !ruby/object:Gem::Dependency
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ hash: 19
72
+ segments:
73
+ - 1
74
+ - 1
75
+ - 0
76
+ version: 1.1.0
77
+ version_requirements: *id004
78
+ name: bundler
79
+ prerelease: false
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ hash: 63
88
+ segments:
89
+ - 1
90
+ - 8
91
+ - 4
92
+ version: 1.8.4
93
+ version_requirements: *id005
94
+ name: jeweler
95
+ prerelease: false
96
+ type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ version_requirements: *id006
108
+ name: rcov
109
+ prerelease: false
110
+ type: :development
111
+ description: Read and write Google Spreadsheets like records
112
+ email: mericson@ericson.net
113
+ executables: []
114
+
115
+ extensions: []
116
+
117
+ extra_rdoc_files:
118
+ - LICENSE.txt
119
+ - README.rdoc
120
+ files:
121
+ - .document
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.rdoc
126
+ - Rakefile
127
+ - VERSION
128
+ - lib/tablespoon.rb
129
+ - tablespoon.gemspec
130
+ - test/helper.rb
131
+ - test/test.rb
132
+ - test/test_tablespoon.rb
133
+ homepage: http://github.com/mericson/tablespoon
134
+ licenses:
135
+ - GPL
136
+ post_install_message:
137
+ rdoc_options: []
138
+
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project:
162
+ rubygems_version: 1.8.24
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: Read and write Google Spreadsheets like records
166
+ test_files: []
167
+