Sha256: 370fb6e52c6e2d0ea1f0760c6e823ec258c48ab7b70f9afed873885c89a4f296

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

= csv_bootstrap

  class FuelType
    csv_bootstrap :url => 'http://spreadsheets.google.com/pub?key=p70r3FHguhimIdBKyVz3iPA'
  end

This will bootstrap your ActiveRecord model with sheet 1 of the Google Docs spreadsheet.

  >> FuelType.bootstrap!
  => true

You can specify other sheets (starts at 1):

  class FuelType
    csv_bootstrap :url => 'http://spreadsheets.google.com/pub?key=p70r3FHguhimIdBKyVz3iPA',
                    :sheet => 1
  end

The gem will always request the CSV-formatted version of the document in question.

== Spreadsheet structure

The first column is always the key.

All of the other columns will be included as attributes, based on the column headers.

  name          emission_factor   units
  coal          5246.89           lbs/short ton
  natural gas   1.25              pounds / therm (nat gas)
  fuel oil      22.51             lbs/gallon

would generate

  a = FuelType.find_or_create_by_name('coal')
  a.update_attributes(:name => 'coal', :emission_factor => '5246.89', :units => 'lbs/short ton')

  a = FuelType.find_or_create_by_name('natural gas')
  a.update_attributes(:name => 'coal', :emission_factor => '1.25', :units => 'pounds / therm (nat gas)')

  a = FuelType.find_or_create_by_name('fuel oil')
  a.update_attributes(:name => 'coal', :emission_factor => '22.51', :units => 'lbs/gallon')

== Copyright

Copyright (c) 2009 Seamus Abshere. See LICENSE for details.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seamusabshere-csv_bootstrap-0.1.0 README.rdoc