seamusabshere-gdocs_bootstrap 0.0.2 → 0.1.0
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/README.rdoc +13 -2
- data/VERSION.yml +2 -2
- data/lib/gdocs_bootstrap.rb +13 -2
- data/test/gdocs_bootstrap_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,14 +1,23 @@
|
|
1
1
|
= gdocs_bootstrap
|
2
2
|
|
3
3
|
class FuelType
|
4
|
-
|
4
|
+
gdocs_bootstrap :url => 'http://spreadsheets.google.com/pub?key=p70r3FHguhimIdBKyVz3iPA'
|
5
5
|
end
|
6
6
|
|
7
|
-
This
|
7
|
+
This will bootstrap your ActiveRecord model with sheet 1 of the Google Docs spreadsheet.
|
8
8
|
|
9
9
|
>> FuelType.bootstrap!
|
10
10
|
=> true
|
11
11
|
|
12
|
+
You can specify other sheets (starts at 1):
|
13
|
+
|
14
|
+
class FuelType
|
15
|
+
gdocs_bootstrap :url => 'http://spreadsheets.google.com/pub?key=p70r3FHguhimIdBKyVz3iPA',
|
16
|
+
:sheet => 1
|
17
|
+
end
|
18
|
+
|
19
|
+
The gem will always set request the CSV version of the document in question.
|
20
|
+
|
12
21
|
== Spreadsheet structure
|
13
22
|
|
14
23
|
The first column is always the key.
|
@@ -31,6 +40,8 @@ would generate
|
|
31
40
|
a = FuelType.find_or_create_by_name('fuel oil')
|
32
41
|
a.update_attributes(:name => 'coal', :emission_factor => '22.51', :units => 'lbs/gallon')
|
33
42
|
|
43
|
+
|
44
|
+
|
34
45
|
== Copyright
|
35
46
|
|
36
47
|
Copyright (c) 2009 Seamus Abshere. See LICENSE for details.
|
data/VERSION.yml
CHANGED
data/lib/gdocs_bootstrap.rb
CHANGED
@@ -4,7 +4,7 @@ require 'open-uri'
|
|
4
4
|
require 'active_support'
|
5
5
|
|
6
6
|
class GdocsBootstrap
|
7
|
-
attr_accessor :url, :target_class_name, :key_sprintf # set in options
|
7
|
+
attr_accessor :url, :target_class_name, :key_sprintf, :sheet # set in options
|
8
8
|
attr_accessor :key_name, :headers, :dictionary, :width
|
9
9
|
|
10
10
|
def bootstrap!
|
@@ -19,7 +19,8 @@ class GdocsBootstrap
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def initialize(options = {})
|
22
|
-
@
|
22
|
+
@sheet = interpret_sheet(options[:sheet])
|
23
|
+
@url = interpret_url(options[:url])
|
23
24
|
@target_class_name = options[:target_class_name]
|
24
25
|
@key_sprintf = options[:key_sprintf] || '%s'
|
25
26
|
end
|
@@ -42,6 +43,16 @@ class GdocsBootstrap
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
46
|
+
def interpret_sheet(sheet)
|
47
|
+
sheet.to_i >= 1 ? sheet.to_i - 1 : 0
|
48
|
+
end
|
49
|
+
|
50
|
+
def interpret_url(url)
|
51
|
+
url = url.gsub(/\&(gid|output)=.*(\&|$)/, '')
|
52
|
+
url << "&output=csv&gid=#{sheet}"
|
53
|
+
url
|
54
|
+
end
|
55
|
+
|
45
56
|
def interpret_key(k)
|
46
57
|
k = k.to_s.strip
|
47
58
|
k = k.to_i if /\%[0-9\.]*d/.match(key_sprintf)
|
data/test/test_helper.rb
CHANGED
@@ -62,4 +62,4 @@ GdocsBootstrapTestHelper::Initializer.start
|
|
62
62
|
|
63
63
|
class Scrum < ActiveRecord::Base; end
|
64
64
|
|
65
|
-
GOOGLE_DOC_URL = 'http://spreadsheets.google.com/pub?key=p70r3FHguhimIdBKyVz3iPA
|
65
|
+
GOOGLE_DOC_URL = 'http://spreadsheets.google.com/pub?key=p70r3FHguhimIdBKyVz3iPA'
|