tablespoon 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/tablespoon.rb +40 -19
- data/tablespoon.gemspec +3 -3
- metadata +87 -98
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/tablespoon.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'google_drive'
|
2
2
|
require 'pp'
|
3
|
+
require 'JSON'
|
3
4
|
|
4
5
|
module Tablespoon
|
5
6
|
|
@@ -17,6 +18,7 @@ module Tablespoon
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def get_table( x, opts = {} )
|
21
|
+
|
20
22
|
if x.class == String
|
21
23
|
return Table.new @doc.worksheet_by_title( x ), opts
|
22
24
|
else
|
@@ -40,7 +42,6 @@ module Tablespoon
|
|
40
42
|
@id_field = opts[:id_field]
|
41
43
|
@include_blank_row = opts[:include_blank_rows] || true
|
42
44
|
|
43
|
-
|
44
45
|
build_column_map
|
45
46
|
|
46
47
|
# build data array
|
@@ -68,11 +69,19 @@ module Tablespoon
|
|
68
69
|
end
|
69
70
|
|
70
71
|
end
|
71
|
-
|
72
|
+
|
72
73
|
def []
|
73
74
|
return @rows[i]
|
74
75
|
end
|
75
76
|
|
77
|
+
def add_row
|
78
|
+
r = Record.new self
|
79
|
+
r.row_num = @ws.num_rows + 1
|
80
|
+
r.data = {}
|
81
|
+
|
82
|
+
r
|
83
|
+
end
|
84
|
+
|
76
85
|
def length
|
77
86
|
return @rows.length
|
78
87
|
end
|
@@ -85,10 +94,16 @@ module Tablespoon
|
|
85
94
|
@rows.each { |i| yield i }
|
86
95
|
end
|
87
96
|
|
88
|
-
def find
|
97
|
+
def find( field, value )
|
98
|
+
@rows.find { |r| r[field] == value }
|
89
99
|
end
|
90
100
|
|
91
|
-
def find_by_id
|
101
|
+
def find_by_id( value )
|
102
|
+
@rows.find { |r| r.id == value }
|
103
|
+
end
|
104
|
+
|
105
|
+
def find_all( field, value )
|
106
|
+
@rows.select { |r| r[field] == value }
|
92
107
|
end
|
93
108
|
|
94
109
|
def save
|
@@ -103,7 +118,22 @@ module Tablespoon
|
|
103
118
|
|
104
119
|
@field_map = column_map.invert
|
105
120
|
end
|
106
|
-
|
121
|
+
|
122
|
+
def dump
|
123
|
+
output = []
|
124
|
+
|
125
|
+
@rows.each do |r|
|
126
|
+
output << r.data
|
127
|
+
end
|
128
|
+
|
129
|
+
output
|
130
|
+
end
|
131
|
+
|
132
|
+
def to_json
|
133
|
+
JSON.dump( self.dump )
|
134
|
+
end
|
135
|
+
|
136
|
+
|
107
137
|
end
|
108
138
|
|
109
139
|
class Record
|
@@ -123,23 +153,14 @@ module Tablespoon
|
|
123
153
|
col_num = get_col_num( field )
|
124
154
|
row_num = @row_num
|
125
155
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
if @id_field
|
130
|
-
id_col_num = get_col_num( @id_field )
|
131
|
-
if @ws[row_num, id_col_num] == id
|
132
|
-
@ws[row_num, col_num] = value
|
133
|
-
else
|
134
|
-
raise "Row has moved"
|
135
|
-
end
|
156
|
+
@ws[row_num, col_num] = value
|
157
|
+
|
158
|
+
@ws.save
|
136
159
|
|
137
|
-
|
138
|
-
@
|
160
|
+
if field == @id_field
|
161
|
+
@id = value
|
139
162
|
end
|
140
163
|
|
141
|
-
@ws.save
|
142
|
-
|
143
164
|
end
|
144
165
|
|
145
166
|
def get_col_num( field )
|
data/tablespoon.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "tablespoon"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
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"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-12-27"
|
13
13
|
s.description = "Read and write Google Spreadsheets like records"
|
14
14
|
s.email = "mericson@ericson.net"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.homepage = "http://github.com/mericson/tablespoon"
|
34
34
|
s.licenses = ["GPL"]
|
35
35
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = "1.8.
|
36
|
+
s.rubygems_version = "1.8.25"
|
37
37
|
s.summary = "Read and write Google Spreadsheets like records"
|
38
38
|
|
39
39
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,109 +1,104 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablespoon
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Matthew Ericson
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
requirement:
|
12
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: google_drive
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
22
17
|
none: false
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 19
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 3
|
30
|
-
- 0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
31
21
|
version: 0.3.0
|
32
|
-
prerelease: false
|
33
22
|
type: :runtime
|
34
|
-
name: google_drive
|
35
|
-
version_requirements: *id001
|
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
23
|
prerelease: false
|
47
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
48
31
|
name: shoulda
|
49
|
-
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
52
33
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 3
|
59
|
-
- 12
|
60
|
-
version: "3.12"
|
61
|
-
prerelease: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
62
38
|
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
63
47
|
name: rdoc
|
64
|
-
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
67
49
|
none: false
|
68
|
-
requirements:
|
50
|
+
requirements:
|
69
51
|
- - ~>
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
segments:
|
73
|
-
- 1
|
74
|
-
- 3
|
75
|
-
- 0
|
76
|
-
version: 1.3.0
|
77
|
-
prerelease: false
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
78
54
|
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
79
63
|
name: bundler
|
80
|
-
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
83
65
|
none: false
|
84
|
-
requirements:
|
66
|
+
requirements:
|
85
67
|
- - ~>
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
segments:
|
89
|
-
- 1
|
90
|
-
- 8
|
91
|
-
- 4
|
92
|
-
version: 1.8.4
|
93
|
-
prerelease: false
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.3.0
|
94
70
|
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.3.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
95
79
|
name: jeweler
|
96
|
-
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.4
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.8.4
|
97
94
|
description: Read and write Google Spreadsheets like records
|
98
95
|
email: mericson@ericson.net
|
99
96
|
executables: []
|
100
|
-
|
101
97
|
extensions: []
|
102
|
-
|
103
|
-
extra_rdoc_files:
|
98
|
+
extra_rdoc_files:
|
104
99
|
- LICENSE.txt
|
105
100
|
- README.rdoc
|
106
|
-
files:
|
101
|
+
files:
|
107
102
|
- .document
|
108
103
|
- Gemfile
|
109
104
|
- Gemfile.lock
|
@@ -117,37 +112,31 @@ files:
|
|
117
112
|
- test/test.rb
|
118
113
|
- test/test_tablespoon.rb
|
119
114
|
homepage: http://github.com/mericson/tablespoon
|
120
|
-
licenses:
|
115
|
+
licenses:
|
121
116
|
- GPL
|
122
117
|
post_install_message:
|
123
118
|
rdoc_options: []
|
124
|
-
|
125
|
-
require_paths:
|
119
|
+
require_paths:
|
126
120
|
- lib
|
127
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
122
|
none: false
|
129
|
-
requirements:
|
130
|
-
- -
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
|
133
|
-
segments:
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
segments:
|
134
128
|
- 0
|
135
|
-
|
136
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
hash: -2779950928584544852
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
131
|
none: false
|
138
|
-
requirements:
|
139
|
-
- -
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
|
142
|
-
segments:
|
143
|
-
- 0
|
144
|
-
version: "0"
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
145
136
|
requirements: []
|
146
|
-
|
147
137
|
rubyforge_project:
|
148
|
-
rubygems_version: 1.8.
|
138
|
+
rubygems_version: 1.8.25
|
149
139
|
signing_key:
|
150
140
|
specification_version: 3
|
151
141
|
summary: Read and write Google Spreadsheets like records
|
152
142
|
test_files: []
|
153
|
-
|