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 CHANGED
@@ -1,14 +1,23 @@
1
1
  = gdocs_bootstrap
2
2
 
3
3
  class FuelType
4
- gdoc_bootstrap :url => 'http://spreadsheets.google.com/pub?key=p70r3FHguhimIdBKyVz3iPA&output=csv&gid=0'
4
+ gdocs_bootstrap :url => 'http://spreadsheets.google.com/pub?key=p70r3FHguhimIdBKyVz3iPA'
5
5
  end
6
6
 
7
- This lets you bootstrap your ActiveRecord models with Google Docs spreadsheets.
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
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 0
4
- :patch: 2
3
+ :minor: 1
4
+ :patch: 0
@@ -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
- @url = options[:url]
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)
@@ -12,7 +12,7 @@ class GdocsBootstrapTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_should_have_url
15
- assert_equal @bootstrap.url, GOOGLE_DOC_URL
15
+ assert_equal @bootstrap.url, GOOGLE_DOC_URL + '&output=csv&gid=0'
16
16
  end
17
17
 
18
18
  def test_should_have_target_class_name
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&output=csv&gid=0'
65
+ GOOGLE_DOC_URL = 'http://spreadsheets.google.com/pub?key=p70r3FHguhimIdBKyVz3iPA'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seamusabshere-gdocs_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere